You code is legal for the reason that an ArrayList implements List, therefore anywhere a list is required you can pass an instance of ArrayList which is called upcasting or the more technical concept around this context programming to an interface.
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF