The Artima Developer Community
Sponsored Link

Weblogs Forum
Announcing Pojomatic 1.0

17 replies on 2 pages. Most recent reply: Apr 28, 2010 12:10 PM by Gregor Zeitlinger

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 17 replies on 2 pages [ « | 1 2 ]
Roland Pibinger

Posts: 93
Nickname: rp123
Registered: Jan, 2006

Re: Configurations and Annotations for equals? Posted: Apr 27, 2010 1:48 PM
Reply to this message Reply
Advertisement
> It's fine other than that it will throw exceptions if
> anything other than a MyObject is passed to it and
> violates the contract of equals if a subclass of MyObject
> with an overridden equals is passed in.

A check for the same class can be added easily. The rest of the method could be simplified with a helper method, e.g.
  isEqual(s, i, o.s, o.i);  

In fact, the 'subclass problem' is a problem of the Java language in general. Java has no types for values (except for the primitive data types), only for objects. But value semantics and inheritance simply don't fit together and produce the aforementioned anomalies.

Ian Robertson

Posts: 68
Nickname: ianr
Registered: Apr, 2007

Re: Announcing Pojomatic 1.0 Posted: Apr 27, 2010 2:05 PM
Reply to this message Reply
> On a side note, the stuff you've done here with Pojomatic
> could be trivially adapted to an Equalator methodology,
> right?

Sort of. Since Pojomatic is configured by annotations, it would only be possible to configure a single Equalator. This is generally a problem with annotations - since they are making statements about the class itself, they are ill suited to talking about a view of a class. (Ever try to put JPA annotations on a single bean to support two different persistence models?).

That said, annotations do provide a certain level of type safety that's hard to get otherwise. Since Pojomatic was designed for the use case of equals, hashCode and toString, and these methods are fundamentally part of the class (for better or worse), annotations are a good fit.

If Java had a type safe way to reference class fields the way it has for referencing classes (i.e. Class<?> c = String.class), then it would be possible to configure alternate Pojomators without sacrificing type safety. Lacking that, the only option I can see for supporting multiple Pojomators for a given class would be one that involved string-based configuration - something like new Pojomator(Bean.class, "name", "age").

Gregor Zeitlinger

Posts: 108
Nickname: gregor
Registered: Aug, 2005

Re: Announcing Pojomatic 1.0 Posted: Apr 28, 2010 12:10 PM
Reply to this message Reply
> The down side to this is, of course, that clients now must
> go to extra work on every insert or retrieval from the
> collection.
The obvious solution is to use a TreeMap, which takes a Comparator - if it is possible to sort the elements.
Sure, the performance is not the same, but this hardly ever matters.
I have used this pattern without any difficulties and hence am puzzled why people reject the Equalator interface with so vigorously.

Flat View: This topic has 17 replies on 2 pages [ « | 1  2 ]
Topic: Syncing Motorola RAZR v3xx With Mac iSync 2.4 Previous Topic   Next Topic Topic: Heron 1.0 Alpha 3 : Compile-Time Reflection, the HeronEdit IDE, and more

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use