Answer the question
In order to leave comments, you need to log in
Is it possible to use a unique primitive or something like that?
Hello, I'm new to Java so don't be too hard on me. ;)
Here, let's say I have a User class. And he has his own Property.
I create an abstract userProperty class of the form:
public abstract class UserProperty {
private String propertyName;
private String propertyValue;
public UserProperty(String propertyName, Integer propertyValue) {
this.propertyName = propertyName;
this.propertyValue = propertyValue;
}
public UserProperty(String propertyName, String propertyValue) {
this.propertyName = propertyName;
this.propertyValue = propertyValue;
}
}
Answer the question
In order to leave comments, you need to log in
public abstract class UserProperty<T> {
private String propertyName;
private T propertyValue;
public UserProperty(String propertyName, T propertyValue) {
this.propertyName = propertyName;
this.propertyValue = propertyValue;
}
}
Гдето там нареализуете класс до нормально
public class UserPropertyString extends UserProperty<String>{
}
или
public class UserPropertyBoolean extends UserProperty<Boolean>{
}
и т.д.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question