March 2005 - Posts

Static method Call with Instance - C# vs J#

class ClassTest
{
     public static void S()
    { }
     public void Test()
    {
        this.S();
    }
}




This is the compiler error
StaticCall.cs(11,3): error CS0176: Static member 'ClassTest.S()' cannot be accessed with an instance reference; qualify it with a type name instead

Why did the J# spec allow this code to compile and not the C# ?
Should we be able to call static methods using a instance as they pretty much belong to the same type definition or should this work like C# which prevents 
static method calls via instance variables because the instance could be null etc and more arguments hence forth.
Just a thought !
with 0 Comments

Getting the Type in J#

Last day a collegue of mine was trying to get the type of a class in J#.

Everyone is would be familiar with the typeof(<MyClass>) in C# right. The question was how to do this in j# as typeof is not supported ?

Loading the assembly was not an option and well we didnt want to make an instance and then get the type from it.

This was what i ended up with .

 

    System.Type t = Class.ToType(System.Windows.Forms.Form.class);

J# java.lang.Class