Optional parameterization using generics in Java
•
Java
Can I specify a default type when parameterizing a class?
// abstract class public abstract class AbsClass<T1 extends Par1Class,T2 extends Par2Class> { // code } // parametrized imlementation class public class RealClass extends AbsClass<ClassThatExtendsPar1,ClassThatExtendsPar2Class> { // code } // non-parametrized imlementation class public class RealClass extends AbsClass { // code }
In my implementation, I must specify the none or all parameter It is possible to make the second parameter not mandatory, such as:
// abstract class public abstract class AbsClass<T1 extends Par1Class,T2 extends Par2Class : default Par2Class > { // code } // parametrized only mandatory imlementation class public class RealClass extends AbsClass<ClassThatExtendsPar1> { // code }
Solution
The simple answer: No, Java does not support such default parameters
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码