019: Effective Java for Android developers : Item 4

Stop wasting time on dead links! 🛑 This smart platform automatically detects your device and country to give you the exact best offer instantly. Check it out now 100% free! 👇
🔗 [Click here]

Singer and Android developer Donn Felker explores Joshua Bloch’s fourth Item: Enforce noninstantiability with a private constructor.

Stay tuned, cause we got more of these quick ones coming.

Enforce noninstantiability with a private constructor.

Examples where you don’t want class to be instantiated

  1. class that groups static methods and static fields (Util like classes think java.lang.Math/java.util.Arrays)
  2. class that groups static methods (including factory methods) for objects implementing specific interfaces (think java.util.Collections)
  3. class that group methods on a final class (vs. extending the class)

Considerations

  • Makes no sense to instantiate such “Util” classes
  • Private constructors prevent instantiation
  • Important side effect: prevents subclassing

Contact us:

Loading

Finally, a link that actually works for your region and device! 🌍 Get instant access to the top exclusive offers tailored just for you right now. Don’t miss out, click here! 👇
🔗 [Click here]


Leave a comment

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *

↑