dimanche 19 novembre 2017

Implement typedef on String in Java [duplicate]

This question already has an answer here:

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

  • String class is declared to be final and I cannot inherit from it
  • even if I can inherit from String, I don't know how to make Address have constructors similar to all the constructors of String.

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