Professional Documents
Culture Documents
Generics In Java
==============
-> Using Generics, we can write our classes / variable / methods which are
indendent of data type
m1 (10) ; // valid
m1 ("hi") ; // in-valid
-> The above method is taking Integer as a parameter (It is tightly coupled). If we
want to pass String as a parameter for m1 ( ) method it is not possible. Compiler
will not accept it.
package in.ashokit;
package in.ashokit;
T obj;
T get() {
return obj;
}
public static void main(String[] args) throws Exception {
package in.ashokit;
T1 obj1;
T2 obj2;
void print() {
System.out.println(obj1 + ", " + obj2);
}
=====================
Generics with wild Cards
======================
=> The above wild card represents Demo class should take any class obj which is
extending from Number class.
Auto Boxing
Auto Unboxing
Var Args
Callable
ExecutorService
Generics
Enums
=============
Enums in Java
=============
enum WEEKDAYS {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY;
}
enum WEEKENDDAYS {
SATURDAY, SUNDAY;
}
-> When we want to declare pre-defined constants then we will use Enums concept.
======================================
Few Points To Remember Related To Enums
======================================
package in.ashokit;
package in.ashokit;
enum WEEKDAYS {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY;
}
enum WEEKENDDAYS {
SATURDAY, SUNDAY;
}
=============
Inner Classes
==============
-> Creating one class inside another class is called as Inner class.
-> The class which contains other class is called as Outer class
-> The Class which is declared inside outer class is called as Inner class.
class A {
class B {
-> Inner classes are hidden from other classes ( only outer class can access inner
class functionality )
====================
Types of Inner classes
=====================
void outerMethod() {
Inner i = new Inner();
i.innerMethod();
}