Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constraints in interface implementation in java [duplicate]

Tags:

java

interface

Possible Duplicate:
Java generics constraint require default constructor like C#

I want to set a constraint to type T that it must have a constructor without parameters. In C# it will be like:

public interface Interface<T> where T : new() { }

Is this feature available in Java?

Update: Is there some trick to make generic type T have a constructor?

like image 726
franza Avatar asked Apr 04 '12 14:04

franza


1 Answers

You cannot define interface for constructors in Java. Nor you cann put any other constraints to type parameters, other than type variance.

like image 95
ahanin Avatar answered Sep 23 '22 13:09

ahanin