UPDATE:
Thanks to @RC for solving this for me:
public class DataHander<I, T extends IDataStore<I>> implements IHollywood<T, I>
From his comment I learned how to fix the ActorImpl:
public class ActorImpl extends DataHander <Long, Actor> implements IHollywood
Solved.
I am currently trying to learn Java and am having some difficulty with generics. I am stuck on how to correctly implement a generic interface using two different type parameters and then extend this new implementation by two other interfaces that extend the original interface.
This is what I am trying to accomplish:
public interface IDataStore<ID> extends Serializable
public interface IHollywood<T extends IDataStore <ID>, ID>
{
List<T> retrieve() throws Exception;
void sotre(T t) throws Exception;
}
public interface IActor extends IHollywood <Actor, Long>
public interface IDirector extends IHollywood <Director, Long>
public class DataHander<T> implements IHollywood <IDataStore<T>, T>
public class ActorImpl implements IActor extends DataHander
public class DirectorImpl implements IDirector extends DataHander
I have two points of confusion:
What is the correct signature for DataHander? Currently I am using public class DataHander<T> implements IHollywood <IDataStore<T>, T>
and I know I am passing T
as two parameters wrongly but can’t figure out the right way
What is the correct way for ActorImpl
and DirectorImpl
to implement IHollywood
and extend DataHander
declaration?
Edit/Update:
I'll try to give more details:
// 1- support serialization
// provide interface to create/store/query persisted data
public interface IDataStore<ID> extends Serializable
public interface IHollywood<T extends IDataStore <ID>, ID>
// 2- provide an interface for Actor specific methods
public class Actor{}...
public interface IActor extends IHollywood <Actor, Long>
// Implement IActor
public class ActorImpl implements IActor
// 3- provide an interface for Director specific methods
public class Director{}...
public interface IDirector extends IHollywood <Director, Long>
// 4- Implement Director
public class DirectorImpl implements IDirector
// 5- Instead of CRUD, I’ll use a better name
// Implent retireve()/store()/find methods
public class DataHander <T> implements IHollywood <IDataStore<T>, T>
1- This way, I can use DataHander to implement retireve()/store()/find() methods of IHollywood
2- I can derive ActorImpl and DirectorImpl from DataHander to use its retireve()/store()/find() methods
3- I know IActor and IDirector extend IHollywood but I do not want to duplicate implementation of retireve()/store()/find() methods of IHollywood. I want the DataHander to implant them and ActorImpl and DirectorImpl to just inherit and use them, besides providing their own specific methods in their own implementation.
I hope this clarifies a bit what I need help with.
Thanks to @RC for solving this for me:
public class DataHander<I, T extends IDataStore<I>> implements IHollywood<T, I>
From his comment I learned how to fix the ActorImpl:
public class ActorImpl extends DataHander <Long, Actor> implements IHollywood
Solved.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments