Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I'm working on migrating a C# project to java.

In the C# project I have a factory class holding a dictionary between Type, and a delegate which creates appropriate type.

I expose a generic method:
T Create<T>()

So the user can write:

var someObject = factory.Create<ISomeInterface> ();

The Create method code is something like:

return (T)dictionary[typeof(T)]();

The question is, How can I do something similar in Java (version 7)?

Thanks a lot for anyone who would help!
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900