The Artima Developer Community
Sponsored Link

Weblogs Forum
A case for member literals in Java

18 replies on 2 pages. Most recent reply: Nov 27, 2007 2:22 PM by Clark Updike

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 18 replies on 2 pages [ « | 1 2 ]
Bruce Chapman

Posts: 8
Nickname: chappy
Registered: Mar, 2003

Re: A case for member literals in Java Posted: Nov 6, 2007 7:55 PM
Reply to this message Reply
Advertisement
what if... ?
@GenerateFieldNameLiterals(Worker.class)
public class Worker {
  private Object runningMutex = new Object();
 
  @GuardedBy(FieldNames.Worker.runningMutex)
  private boolean running;
}


and the line
@GenerateFieldNameLiterals(Worker.class)
caused the generation (via a javax.annotation.processing.Processor) of the following
class FieldNames {
    static class Worker {
        static final String runningMutex = "runningMutex";
        static final String running = "running";
    }
}


You'd then get your compile time errors if you misspelled something.

If you needed Field objects and Method Objects you could do similar.

Gregor Zeitlinger

Posts: 108
Nickname: gregor
Registered: Aug, 2005

Re: O.K., I'm confused Posted: Nov 12, 2007 5:46 PM
Reply to this message Reply
> According to Google, there is no EqualsHelper.create().
But there is the EqualsBuilder (http://commons.apache.org/lang/api/org/apache/commons/lang/builder/EqualsBuilder.html), which would benefit from method literals.

I have also wanted method literals for some time.

Jeroen Wenting

Posts: 88
Nickname: jwenting
Registered: Mar, 2004

Re: O.K., I'm confused Posted: Nov 13, 2007 9:12 AM
Reply to this message Reply
Sure. While we're at it let's also do away with typechecking so we can create and pass void as a valid parameter type and have a method thus accept anything (literal or Object) at all.
And implement operator overloading, multiple inheritance, untyped types, pointers, and everything else that makes C so nice (or Ruby, Python, fill in your favourite language).

'Cause that's the real reason all those "features" and "improvements" are proposed, because they're in some other language that someone likes and "Java is dead" if it doesn't have it in the next version.

Clark Updike

Posts: 11
Nickname: clark
Registered: Apr, 2002

Re: A case for member literals in Java Posted: Nov 27, 2007 2:22 PM
Reply to this message Reply
I've often wondered what things would be like if there was tighter integration between XML and java. What if you could reference class constant pool values from XML files? Or conversely could reference schema elements from java classes at compile time (maybe by importing a URL reference or something)? Imagine how many more runtime errors would become design time errors.

Maybe there's reasons that it would be a bad idea, but every time I find myself sprinkling literals in java, jsp, xml, xhtml, etc because that's how it has to be done, it makes me wish the capability were there. Heck, why can't the compiler let you use enum instances anywhere a String instance was legal (including annotations).

Flat View: This topic has 18 replies on 2 pages [ « | 1  2 ]
Topic: A case for member literals in Java Previous Topic   Next Topic Topic: Python 3000 alpha 1 Released!


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us