Generics of the reference is important. So
List list = new ArrayList<String>();
makes no sense. It must be
List<String> list = new ArrayList<String>();
If you don not provide at generics for the reference type(not the actual object type) it is taken to be as Object
. So you can add anything to it.
Also generics is a compile time phenomenon. So when you say how it works it means how your code is compiling without compilation errors. It is for a simple reason that no generics associated with the reference Object and hence is taken as Object(default).