Showing posts with label generics. Show all posts
Showing posts with label generics. Show all posts

Thursday, June 30, 2016

Benefits of Generics

One beneit of using generic classes should now be obvious:
improved correctness. Incorrect types of objects can no longer
be entered into a list. While erroneous attempts to insert
an element could previously be detected only during testing
(and testing can never be complete), they are now detected at
compile time, and type correctness is guaranteed. In addition,
if there is such an error, it will be reported at the point of the
incorrect insertion—not at the
point of retrieving the element,
which is far removed from the
actual error location.
There is, however, a second
beneit: readability. By
explicitly specifying the element
type of collections,
you are providing useful information to human readers of
your program as well. Explicitly saying what type of element
a collection is intended for can make life easier for a
maintenance programmer.

Monday, December 7, 2015

What is array subtyping is covariant means ?

It means array DOVE[] is considered to be subtype of BIRD[] if DOVE is a subclass of BIRD.
example
Integer[] ints = new Integer[]{9,99};
Number[] nums =  ints;
nums[1] = 1.9; // here it will throw array store exception
According to the substitution principle the assignment on the second line is legal
but the exception will be throws at the run time on the third line.
Because whenever an array is created then it tagged with its reified type. here it is integer.
eventhough it is assigned to the Number (super type)  type here internally it points to it
Integer type so it throws exception at run time when it detects a float value assigned.

While in contrats for generics the subtype relation is invariant, means
List<DOVE> is not considered to be subtype of List<BIRD>.

example
List<Integer> intList =  Arrays.asList(1,2,3,4,5,6,7,8,9);
List<Number>  numList = intList; // here it will show compile time error


But here with wild card we can achieve the covariant
in that case here List<DOVE> is considered to be subtype of List<? extends BIRD>.

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...