If given a choice, choose generics. Joshua also talked about a cool mind expanding pattern, the Typesafe Heterogeneous Container THC pattern, which he talked about last year.
Joshua said that generics are tricky but well worth learning as they make your code better and safe. Joshua also recommended the use of the Override annotation every time you want and think you are overriding a method because sometimes you are overloading a method instead. And finally, final is the new private. Minimize mutability where ever possible, but be caution when working with serialization or cloneable.
Technorati Tags: javaone , javaone , generics , java , best practices. Name required. Mail will not be published required. Enter your email address to subscribe to this blog and receive notifications of new posts by email. Email Address. The following tips deal with Java generics. Technorati Tags: javaone , javaone , generics , java , best practices Love it? Share it! Facebook Reddit Twitter. This entry was posted on Wednesday, May 30th, at amand is filed under.
You can follow any responses to this entry through the RSS 2. You can leave a response , or trackback from your own site. And if you do require it, how would a singleton extend another class? Would that class also be a singleton? If not, how does that work? If it is, what happens if someone else extends it too? You'll have two instances of a singleton base class.
Singleton is a seriously deprecated anti-pattern, I think the only fair use for this is to implement constants, which enums do handily. Show 2 more comments. Active Oldest Votes. I find using fields to be simpler. Enums can't be inherited, True, but having multiple singletons is suspect in itself. If you want to provide a skeleton class you need to create a helper class A helper class doesn't have any state. Improve this answer. Peter Lawrey Peter Lawrey k 73 73 gold badges silver badges bronze badges.
Add a comment. Enums can't be inherited And it's one of the best parts of enums being singletons. If you can inherit from a singleton, it's not a singleton any more. Stefan Ferstl Stefan Ferstl 4, 3 3 gold badges 29 29 silver badges 39 39 bronze badges.
Where did you find this sentence? Enum values are guaranteed to exist only once. Is there official documentation? Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked Related Hot Network Questions.
0コメント