C# to Java: where T : new() Syntax

Posted by Shiftbit on Stack Overflow See other posts from Stack Overflow or by Shiftbit
Published on 2010-04-12T01:35:35Z Indexed on 2010/04/12 1:43 UTC
Read the original article Hit count: 366

Filed under:
|
|

I am porting some C# code over to Java. I am having trouble with the where Syntax, specifically new(). I understand that where is similar to Java's generic: T extends FOO.

How I can replicate the new() argument in Java?

"The new() Constraint lets the compiler know that any type argument supplied must have an accessible parameterless--or default-- constructor." - MSDN

ie:

public class BAR<T> : BAR
       where T : FOO, new()

Right now I have:

public class BAR<T extends FOO> extends ABSTRACTBAR {
   public HXIT(T t){ 
        this.value = t;
   }
   ....
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about java