Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In Java

XML
public class A<T>
 {
     private T response;


     private A(T response)
     {
         this.response = response;
     }

     public static <T> A<T> buildError()
     {
         A<T> trans = new A<T>(null);
         return trans;
     }

 }



I can call buildError method Like A.BuildError() without giving generic type.

In C#
XML
public class A<T>
 {
     private T response;


     private A(T response)
     {
         this.response = response;
     }

 
     public static A<T> buildError()
     {
         A<T> trans = new A<T>(null);
         return trans;
     }

 }


In C#,Can I call buildError method Like A.BuildError() without giving generic type.
Posted

1 solution

No - Since there is no parameter or other information to identify the type that can be returned, you need to specify it when you call the method.

But that won't even compile: null is not an object and has no type! So this line:
C#
A<t> trans = new A<t>(null);
will just give you a compilation error.
 
Share this answer
 
v2

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