JavaLearner's profile picture. Java Programmer, Continuous  Java Learner Mostly tweet about Java Learning,Blog Links,Books   #Java #Programming #LearningJava #JDK

Java Learner

@JavaLearner

Java Programmer, Continuous Java Learner Mostly tweet about Java Learning,Blog Links,Books #Java #Programming #LearningJava #JDK

Final vs Effective Final...Java8


Use instance fields instead of ordinals.


Consider the strategy enum pattern if multiple enum constants share common behaviors.


Enum Strategy pattern : Example

JavaLearner's tweet image. Enum Strategy pattern : Example

Sometimes when you need to have set of behavior inside Enum for enum constants use enum strategy pattern.


Constant-specific method implementations: Example

JavaLearner's tweet image. Constant-specific method implementations: Example
JavaLearner's tweet image. Constant-specific method implementations: Example

Constant-specific method implementations:Declare an abstract method in the enum type, and override it with a concrete method for each const.


If you know all possible values of constant at compile time, use Enums.


values() methods on Enums, would return the elements in the order they are declared.


Enums are by their nature immutable, so all fields should be final!


Enums provide implementations of all the Object methods.,Implement Comparable & Serializable.


One of great benefits of Enums are , they provide compile time safety.


Enum types are effectively final.Clients can neither create instances of it nor extend it,there can only be declared enum constants.


Enums are classes that export one instance for each enumeration constant via a public static final field.


Use enums instead of int constants


Never call public methods from Class Constructor.


It's illegal to use primitive types in generics. e.g List<int> is not allowed. Use boxed primitive objects. But List<int[]> is allowed.#java


Generics,are implemented by erasure.i.e they enforce their type constraints only at compile time & erase their element type info at runtime.


Loading...

Something went wrong.


Something went wrong.