How do I write an equivalent of this in Java?
// C++ Code
template< class T >
class SomeClass
{
private:
T data;
public:
SomeClass()
{
}
void set(T data_)
{
data = data_;
}
};
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.
You probably also want to make the class itself public, but that’s pretty much the literal translation into Java.
There are other differences between C++ templates and Java generics, but none of those are issues for your example.