Re: Java syntax extension proposal



Lew wrote:
Daniel Pitts wrote:
As I recall, there was a JSR proposal for something that was like a static import, but it made the static method call look like an instance call.

You can already reference a static method through an instance, but most sources I've read regard that as a bad practice. Eclipse even supports a warning about that.

How did the suggested feature differ?

It allows a static method from one class (Let's say Foo) be called on an instance variable of another class (Let's say String).

For example:
// Foo.java:

class Foo {
public static String doSomething(String string) { ... }
}




// Main.java

/*Magic Static Import statment that says allow String.doSomething() to be called. Something like import migrate Foo.doSomething to String */

class Main {
public static void main(String...args) {
String myString = "This is a test";
myString.doSomething(); // Sugar for Foo.doSomething(myString)
}
}

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.



Relevant Pages

  • Re: C++ in C#...
    ... Firts, you never assign to s, so you return a null reference. ... Second, Format is a static method, though C++ allows you to call a static ... Third, the format specifiers %s and %c are not valid in C++/CLI, search the ... String^ color; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Tsomething(nil).SomeMethod and Tsomething(garbage).SomeMethod should halt the debugger.
    ... solves the case where only a single reference to the object exists. ... >> reference to ensure it's not nil before calling the destructor. ... the first but not the second, because the string Result is initialised. ... A call to a static method is translated to a fixed ...
    (alt.comp.lang.borland-delphi)
  • Re: OO conventions
    ... subclass object (likely by passing a string to the constructor, e.g., ... Image.opendefined as a static method (wait...is that ...
    (comp.lang.python)
  • Re: Can i pass a SqlConnection object with opened connection to a method/function as a parameter?
    ... methods in your long concatenated string, ... DataTools.EscapeMask method (a static method, apparently), or the ... > connection and what you do with it when you get it ... >> the existed opened sqlconnection object to do it and pass the object to ...
    (microsoft.public.dotnet.framework)
  • Re: Accessing functions defined in Global.asax
    ... Anjali Lourda wrote: ... > public function getNameas String ... better off creating a class with a static method and referencing the ... Ryan Walberg, B.Sc., MCSD, MCSD for .NET ...
    (microsoft.public.dotnet.framework.aspnet)