When to use Interface and Model in TypeScript / Angular

Interfaces are only at compile time. This allows only you to check that the expected data received follows a particular structure. For this you can cast your content to this interface: this.http.get(‘…’) .map(res => <Product[]>res.json()); See these questions: How do I cast a JSON object to a typescript class How to get Date object from … Read more

Check if a Class Object is subclass of another Class Object in Java

You want this method: boolean isList = List.class.isAssignableFrom(myClass); where in general, List (above) should be replaced with superclass and myClass should be replaced with subclass From the JavaDoc: Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface … Read more

Java: how do I get a class literal from a generic type?

You can’t due to type erasure. Java generics are little more than syntactic sugar for Object casts. To demonstrate: List<Integer> list1 = new ArrayList<Integer>(); List<String> list2 = (List<String>)list1; list2.add(“foo”); // perfectly legal The only instance where generic type information is retained at runtime is with Field.getGenericType() if interrogating a class’s members via reflection. All of … Read more

How do I get a PHP class constructor to call its parent’s parent’s constructor?

The ugly workaround would be to pass a boolean param to Papa indicating that you do not wish to parse the code contained in it’s constructor. i.e: // main class that everything inherits class Grandpa { public function __construct() { } } class Papa extends Grandpa { public function __construct($bypass = false) { // only … Read more

Why use ‘virtual’ for class properties in Entity Framework model definitions?

It allows the Entity Framework to create a proxy around the virtual property so that the property can support lazy loading and more efficient change tracking. See What effect(s) can the virtual keyword have in Entity Framework 4.1 POCO Code First? for a more thorough discussion. Edit to clarify “create a proxy around”: By “create … Read more

‘POCO’ definition

“Plain Old C# Object” Just a normal class, no attributes describing infrastructure concerns or other responsibilities that your domain objects shouldn’t have. EDIT – as other answers have stated, it is technically “Plain Old CLR Object” but I, like David Arno comments, prefer “Plain Old Class Object” to avoid ties to specific languages or technologies. … Read more

Java: Multiple class declarations in one file

Javac doesn’t actively prohibit this, but it does have a limitation that pretty much means that you’d never want to refer to a top-level class from another file unless it has the same name as the file it’s in. Suppose you have two files, Foo.java and Bar.java. Foo.java contains: public class Foo Bar.java contains: public … Read more