What is the maximum number of type parameters you used in a java class?
Example for 4:
class MyClass<A, B, C, D> {
}
What is the maximum number of type parameters you used in a java class?
Example for 4:
class MyClass<A, B, C, D> {
}
Never used more then 2. Actually, I've never seen more then 2 type parameters in any class in java.* package.
The representation of type parameters in the JDK 1.5 or greater classfile format don't impose any limits on the number of type parameters. So I would say there is no limit. (The information is in this document ... search for the word "signature".)
By contrast, the number of methods, fields and interfaces is 2**16 because the classfile format has a 16 bit counts for these in the ClassFile
descriptor.
I have a Quadruple class which is a poor man's tuple. Obviously, it takes four parameters.
I think I was once trying to create a framework for board-based games that took 7 type parameters. I never completed it but it’s quite probable that that list would have grown some more. :)
public interface Board<B extends Board<B, C, M, P, Pi, S, T>, C extends BoardColor, M extends Move<M, P, Pi, S>, P extends BoardPlayer<B, C, M, P, Pi, S, T>, Pi extends BoardPiece<B, C, M, P, Pi, S, T>, S extends BoardState<B, C, M, P, Pi, S, T>, T extends BoardTile<B, C, M, P, Pi, S, T>> {
…
}
When using Functional Java library, you quite often need four to five type parameters. For instance, see this example. More examples here.