How to merge objects?

Copy var src = { name: ‘Apple’, price: 5}; var dst= angular.copy(src); deep copy Extend: var mergedObject = angular.extend(dst, src1, src2, …) shallow copy Merge: var mergedObject = angular.merge(dst, src); since angular 1.4+ deep (recursively) copy If you want to not overwrite with null, you can use this. Object.assign(): let movie2 = Object.assign({}, movie1, { … Read more

Java why interface extends interface

The significant reasons depend entirely on what the interface is supposed to do. If you have an interface Vehicle and an interface Drivable it stands to reason that all vehicles are drivable. Without interface inheritance every different kind of car class is going to require class ChevyVolt implements Vehicle, Drivable class FordEscort implements Vehicle, Drivable … Read more

Scala – extends vs with

If you have multiple classes or traits to inherit, the first one is always extends, and the following >=0 class/trait to be withs. But remember that you can only inherit <=1 (abstract) class, which means if you need to inherit a parent class (Parent), it should always comes at first of the form … extends … Read more

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

Interface extends another interface but implements its methods

Why does it implement its methods? How can it implement its methods when an interface can’t contain method body? How can it implement the methods when it extends the other interface and not implement it? What is the purpose of an interface implementing another interface? Interface does not implement the methods of another interface but … Read more