[chuck-users] accessing static methods through an instance?

Robert Poor rdpoor at gmail.com
Sun Jan 24 18:22:45 EST 2010

[Coincidentally, Stefan's message about identically named (instance) methods
arrived as I was composing this note.  It's possible this is the same thing,
but with a different twist...]

One might expect that an instance reference calls an instance method and a
class reference calls a static method even if they have the same name, but
it ain't so.  And the compiler doesn't issue any warning.  Consider the

==== file: fn.ck
public class F {
    fun static void method() { <<< "static method()" >>>; }
    fun void method() { <<< "instance method()" >>>; }
F.method(); // call method via class
(new F).method(); // call method via instance
==== produces:
"static method()" : (string)
"static method()" : (string)

I can convince myself that this isn't really a bug, if "static" really means
"make this variable or method shared by all instances", but it would be nice
if the compiler warned you about identically named methods.  (Note that the
compiler DOES issue an error for identically named variables.)

- Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20100124/88271f38/attachment.htm>

More information about the chuck-users mailing list