Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generics for creation method

796386Sep 1 2010 — edited Sep 13 2010
Hi,
I have a Factory class for creating various objects.
The API is like this:
public static <T extends BusinessEntity> T createEntity(Class<T> t)
The usage is as:
Car car = Factory.create(Car.class);
Notice I have to specy the class type as a parameter.

I note with things like the collections framework, I don't have to specify a class parameter. For example, I can just do

List<Car> cars = new ArrayList<Car>();

I was wondering is there anyway I can improve my Factory method, so I don't have to specify a .class parameter.

Thanks a million.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2010
Added on Sep 1 2010
4 comments
2,326 views