This is because there is no implicit way to assign the value of a complex object.
When you execute int a = 3; or double b = 2.5; , you can indirectly specify the type on the right side.
In OOP, you need to use a constructor, so you need to make new TypeName() . It also gives you the ability to pass parameters to customize the object.
Another reason is the use of interfaces. So you can do:
MyInterface blah = new InterfaceImplementation(); MyInterface bar = new AnotherInterfaceImplementation();
and even:
ParentClass foo = new DerivedClass();
This is due to the fact that when working with interfaces, you usually do not want to set the type of a variable as an implementation of the interface, but the interface itself. Otherwise, there would be no way to indicate which implementation to use.
Another useful thing is generics:
List<SomeType> myList = new ArrayList<SomeType>();
Java 7 will simplify this for
List<SomeType> myList = new ArrayList<>();
so you don’t have to type <SomeType> twice (this is especially painful in Maps).
Vivin paliath
source share