This question already has an answer here:
- Extend java.lang.String 4 answers
I have read some questions about typedef not existing in Java, and some specific example of simulating it in Java. But I can't figure out how to implement it for a very simple case.
Suppose I am given some incomplete code having an undefined class Address. Address behaves just like String. In Java, I can't do things like in C:
typedef String Address;
I can't do
class Address extends String {
}
because
Stringclass is declared to befinaland I cannot inherit from it- even if I can inherit from
String, I don't know how to makeAddresshave constructors similar to all the constructors ofString.
So how would you create a class which is basically the same as a predefined final class? Is there some design pattern that can help?
Thanks.
Aucun commentaire:
Enregistrer un commentaire