class Pair<A,B> {
final A first;
final B sec;
Pair(A f, B s){
this.first = f;
this.sec = s;
}
}
Is there a way to ensure that A and B are immutable types ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. There is no way to identify, let alone bound, a type as being immutable.
You could create a marker interface (one without methods, like
Serializable) that is used in your project to identify immutable classes, and have your team adhere to it.For example: