Whenever we code an anonymous inner class in java, we might have come across the following compile time error.

compile error

What is this error and why does it want the local variable to be effectively final?

According to Oracle Java docs, anonymous classes are defined as

Anonymous classes enable you to make your code more concise. They enable you to declare and instantiate a class at the same time. They are like local classes except that they do not have a name. Use them if you need to use a local class only once.

Anonymous inner classes makes the code more…

In this article we’ll see why we need generics in java and how they work.

The following code snippet represents a method which will find the maximum value in the given list.

private static Integer findMax(List inputList)
Integer max = (Integer)inputList.get(0);
for(int i = 1; i < inputList.size(); i++)
Integer currentValue = (Integer)inputList.get(i);
if(max.compareTo(currentValue) < 0)
max = currentValue;
return max;

We will call this method with the array list shown below. We have added two integers to the list. …

Consider you own a map (shown below) of a territory that you are not familiar with.

Assume you are initially at the starting point and the map shows there are two routes to reach that black house.

You take route A and after some distance you encounter a fallen tree which is blocking your way.

Your Original Map

So you look at the map and see that you have to go all the way back and follow route B. So you go back and take route B.


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store