Generics : List

List<Dog> is a subtype of List<? extends Animal>, but not a subtype of List<Animal>. Why is List<Dog> not a subtype of List<Animal>? Consider the following example: void mySub(List<Animal> myList) { myList.add(new Cat()); } If you were allowed to pass a List<Dog> to this function, you would get a run-time error. EDIT: Now, if we use … Read more

Extending an Object in Javascript

You want to ‘inherit’ from Person’s prototype object: var Person = function (name) { this.name = name; this.type=”human”; }; Person.prototype.info = function () { console.log(“Name:”, this.name, “Type:”, this.type); }; var Robot = function (name) { Person.apply(this, arguments); this.type=”robot”; }; Robot.prototype = Person.prototype; // Set prototype to Person’s Robot.prototype.constructor = Robot; // Set constructor back to … Read more