Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.ParameterizedType;
- import java.lang.reflect.Type;
- final class Method<T> {
- private Class<T> typeArgumentClass;
- public Method(Class<T> typeArgumentClass) {
- this.typeArgumentClass = typeArgumentClass;
- }
- public T instance() throws Exception {
- return typeArgumentClass.newInstance();
- }
- }
- /* Name of the class has to be "Main" only if the class is public. */
- class A<T>{
- public Method<T> temp;
- public A(T typeArgumentClass) {
- temp = new Method(typeArgumentClass.getClass());
- }
- public String toString(){
- try {
- return "A<"+temp.instance().toString()+">";
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- }
- class B<T>{
- public Method<T> temp;
- public B(T typeArgumentClass) {
- temp = new Method(typeArgumentClass.getClass());
- }
- public String toString(){
- try {
- return "B<"+temp.instance().toString()+">";
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- }
- class C{
- public String toString(){
- return "C";
- }
- }
- class test
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- B<C> b = new B<C>(new C());
- //System.out.println(b.toString());
- //A<B> a = new A<B>(b);
- A<B<C>> a = new A<B<C>>(b);
- System.out.println(a.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement