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

I’m playing around with Java’s reflection API and trying to handle some fields. Now I’m stuck with identifying the type of my fields. Strings are easy, just do myField.getType().equals(String.class). The same applies for other non-derived classes. But how do I check derived classes? E.g. LinkedList as subclass of List. I can’t find any isSubclassOf(…) or … Read more

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

I need to have a class constructor in PHP call its parent’s parent’s (grandparent?) constructor without calling the parent constructor. // main class that everything inherits class Grandpa { public function __construct() { } } class Papa extends Grandpa { public function __construct() { // call Grandpa’s constructor parent::__construct(); } } class Kiddo extends Papa … Read more

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

In the following blog: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx The blog contains the following code sample: public class Dinner { public int DinnerID { get; set; } public string Title { get; set; } public DateTime EventDate { get; set; } public string Address { get; set; } public string HostedBy { get; set; } public virtual ICollection<RSVP> RSVPs … Read more

What is the difference between functions and classes to create reusable widgets?

I have realized that it is possible to create widgets using plain functions instead of subclassing StatelessWidget. An example would be this: Widget function({ String title, VoidCallback callback }) { return GestureDetector( onTap: callback, child: // some widget ); } This is interesting because it requires far less code than a full-blown class. Example: class … Read more

difference between variables inside and outside of __init__()

Is there any difference at all between these classes besides the name? class WithClass (): def __init__(self): self.value = “Bob” def my_func(self): print(self.value) class WithoutClass (): value = “Bob” def my_func(self): print(self.value) Does it make any difference if I use or don’t use the __init__ method for declaring the variable value? My main worry is … Read more