Fair enough.  Looks like your original workaround is the way to go.  I haven't 
come across a situation where I needed to override methods in enums.

Tim


On 07/06/2013, at 9:22 PM, Musall Maik wrote:

> 
> Uh, I should have made the implementation more different in the two. In 
> general, the enums I have are more lengthy, and they do all sorts of 
> different stuff to compute something in their methods. They can't share a 
> common implementation, or at least there could be a common one, but the point 
> would be that a few enum instances would need to override the implementation, 
> not just differ in fixed values.
> 
> 
> Am 07.06.2013 um 12:45 schrieb D Tim Cummings <t...@triptera.com.au>:
> 
>> public enum Status {
>>   one (1),
>>   two (2);
>>   private final int days;
>>   Status(int days) {
>>     this.days = days;
>>   }
>>   public DateTime computeValue() {
>>     return new DateTime().plusDays(days);
>>   }
>> }
>> 
>> On 07/06/2013, at 8:34 PM, Musall Maik wrote:
>> 
>>> 
>>> Got that already by private mail. All right, let's modify the example. 
>>> Returning a fixed string was oversimplifying.
>>> 
>>> 
>>>     public enum Status {
>>>         one { @Override public DateTime computeValue() { new 
>>> DateTime().plusDays( 1 ); },
>>>         two { @Override public DateTime computeValue() { new 
>>> DateTime().plusDays( 2 ); };
>>>         public abstract DateTime computeValue();
>>>     }
>>> 
>>> 
>>> Maik
>>> 
>>> 
>>> Am 07.06.2013 um 12:27 schrieb D Tim Cummings <t...@triptera.com.au>:
>>> 
>>>> Another workaround which is less ugly.
>>>> 
>>>> public enum Status {
>>>>   one ("eins"),
>>>>   two ("zwei");
>>>>   private final String description;
>>>>   Status(String description) {
>>>>     this.description = description;
>>>>   }
>>>>   public String description() {
>>>>     return description;
>>>>   }
>>>> }
>>>> 
>>>> Tim
>>>> 
>>>> 
>>>> On 07/06/2013, at 5:58 PM, Musall Maik wrote:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> some time ago, I discovered the following problem with Enums and WO 
>>>>> bindings (broken down to a simple example):
>>>>> 
>>>>>    package com.foo.bar;
>>>>>    public class MyClass {
>>>>>        public static enum Status {
>>>>>            one    { @Override public String description() { return 
>>>>> "eins"; } },
>>>>>            two    { @Override public String description() { return 
>>>>> "zwei"; } };
>>>>>            public abstract String description();
>>>>>        }
>>>>>    }
>>>>> 
>>>>> While this works nicely in all Java code, WO bindings will not see the 
>>>>> overridden description() implementations. At least not when using Java 
>>>>> packages (it seems to work if everything is in the default package, but 
>>>>> that doesn't help me). You get an error like:
>>>>> 
>>>>>    java.lang.IllegalAccessException: Class 
>>>>> com.webobjects.foundation.NSKeyValueCoding$ValueAccessor$1 can not access
>>>>>    a member of class com.foo.bar.MyClass$Status$1 with modifiers "public"
>>>>> 
>>>>> or, if using JRebel, you get
>>>>> 
>>>>>    java.lang.IllegalAccessException: Class<?> 
>>>>> com.webobjects.foundation.NSKeyValueCoding$ValueAccessor$1 can not access
>>>>>    com.foo.bar.MyClass$Status$1!
>>>>> 
>>>>> My current workaround:
>>>>> 
>>>>>    package com.foo.bar;
>>>>>    public class MyClass {
>>>>>        public static enum Status {
>>>>>            one    { @Override String descriptionImpl() { return "eins"; } 
>>>>> },
>>>>>            two    { @Override String descriptionImpl() { return "zwei"; } 
>>>>> };
>>>>>            abstract String descriptionImpl();
>>>>>            public String description() { return descriptionImpl(); }
>>>>>        }
>>>>>    }
>>>>> 
>>>>> which works but is ugly. Now I'm about to implement another Enum with a 
>>>>> lot of methods and it bothers me. Anyone an idea how to improve the 
>>>>> situation?
>>>>> 
>>>>> Thanks
>>>>> Maik
>>>>> _______________________________________________
>>>>> Do not post admin requests to the list. They will be ignored.
>>>>> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
>>>>> Help/Unsubscribe/Update your Subscription:
>>>>> https://lists.apple.com/mailman/options/webobjects-dev/tim%40triptera.com.au
>>>>> 
>>>>> This email sent to t...@triptera.com.au
>>>> 
>>> 
>> 
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/maik%40selbstdenker.ag
>> 
>> This email sent to m...@selbstdenker.ag
> 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to