Autoboxing in EMF fails [message #417844] |
Wed, 26 March 2008 19:44 |
|
Hi,
I read once that EMF 2.3 had autoboxing implemented.
Does any know why the following doesn't work?
Best regards, Lars
Model:
package auto;
import java.lang.String;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import java.util.List;
/**
*
* @model
*/
public interface IBox extends EObject {
/**
*
* @model containment = "true"
*/
public EList<String> getNames();
}
Test code:
package test;
import auto.AutoFactory;
import auto.IBox;
import auto.impl.AutoFactoryImpl;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
AutoFactory factory = AutoFactoryImpl.eINSTANCE;
IBox box = factory.createIBox();
box.getNames().add("Moin");
}
}
|
|
|
|
Re: Autoboxing in EMF fails [message #417847 is a reply to message #417846] |
Wed, 26 March 2008 19:55 |
|
Hi Ed,
The compliance level for EMF and Java is set to 6.0 and I receive the
following error:
Exception in thread "main" java.lang.ClassCastException: java.lang.String
cannot be cast to org.eclipse.emf.ecore.InternalEObject
at org.eclipse.emf.ecore.util.EcoreEList.inverseAdd(EcoreEList. java:267)
at
org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
at test.Main.main(Main.java:15)
Best regards, Lars
"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fse9ft$gmn$1@build.eclipse.org...
> Lars,
>
> Comments below.
>
>
> Lars Vogel wrote:
>> Hi,
>>
>> I read once that EMF 2.3 had autoboxing implemented.
>>
> Autoboxing is a feature of Java 5.0, so I'm not sure what it means for EMF
> to implement it.
>> Does any know why the following doesn't work?
>>
>> Best regards, Lars
>>
>> Model:
>>
>> package auto;
>>
>> import java.lang.String;
>> import org.eclipse.emf.common.util.EList;
>> import org.eclipse.emf.ecore.EObject;
>> import java.util.List;
>>
>> /**
>> *
>> * @model
>> */
>> public interface IBox extends EObject {
>> /**
>> *
>> * @model containment = "true"
>> */
>> public EList<String> getNames();
>> }
>>
>> Test code:
>>
>> package test;
>>
>> import auto.AutoFactory;
>> import auto.IBox;
>> import auto.impl.AutoFactoryImpl;
>>
>> public class Main {
>>
>> /**
>> * @param args
>> */
>> public static void main(String[] args) {
>> AutoFactory factory = AutoFactoryImpl.eINSTANCE;
>> IBox box = factory.createIBox();
>> box.getNames().add("Moin");
>> }
>> }
>>
>>
> What's not working? You're sure you've set source compatibility to 5.0
> for the JDT's preferences and you've set the GenModel's Compliance Level
> to 5.0?
>>
>>
>>
|
|
|
Re: Autoboxing in EMF fails [message #417848 is a reply to message #417847] |
Wed, 26 March 2008 19:58 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------000000000003040205030509
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lars,
Oh. I see you've set containment="true" which makes EMF think this
feature is an EReference rather than an EAttribute; hence you can only
add EObjects to it and java.lang.String isn't an EObject. You need to
remove the containment="true"
Lars Vogel wrote:
> Hi Ed,
>
> The compliance level for EMF and Java is set to 6.0 and I receive the
> following error:
>
> Exception in thread "main" java.lang.ClassCastException: java.lang.String
> cannot be cast to org.eclipse.emf.ecore.InternalEObject
> at org.eclipse.emf.ecore.util.EcoreEList.inverseAdd(EcoreEList. java:267)
> at
> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
> at test.Main.main(Main.java:15)
>
> Best regards, Lars
>
> "Ed Merks" <merks@ca.ibm.com> wrote in message
> news:fse9ft$gmn$1@build.eclipse.org...
>
>> Lars,
>>
>> Comments below.
>>
>>
>> Lars Vogel wrote:
>>
>>> Hi,
>>>
>>> I read once that EMF 2.3 had autoboxing implemented.
>>>
>>>
>> Autoboxing is a feature of Java 5.0, so I'm not sure what it means for EMF
>> to implement it.
>>
>>> Does any know why the following doesn't work?
>>>
>>> Best regards, Lars
>>>
>>> Model:
>>>
>>> package auto;
>>>
>>> import java.lang.String;
>>> import org.eclipse.emf.common.util.EList;
>>> import org.eclipse.emf.ecore.EObject;
>>> import java.util.List;
>>>
>>> /**
>>> *
>>> * @model
>>> */
>>> public interface IBox extends EObject {
>>> /**
>>> *
>>> * @model containment = "true"
>>> */
>>> public EList<String> getNames();
>>> }
>>>
>>> Test code:
>>>
>>> package test;
>>>
>>> import auto.AutoFactory;
>>> import auto.IBox;
>>> import auto.impl.AutoFactoryImpl;
>>>
>>> public class Main {
>>>
>>> /**
>>> * @param args
>>> */
>>> public static void main(String[] args) {
>>> AutoFactory factory = AutoFactoryImpl.eINSTANCE;
>>> IBox box = factory.createIBox();
>>> box.getNames().add("Moin");
>>> }
>>> }
>>>
>>>
>>>
>> What's not working? You're sure you've set source compatibility to 5.0
>> for the JDT's preferences and you've set the GenModel's Compliance Level
>> to 5.0?
>>
>>>
>>>
>
>
>
--------------000000000003040205030509
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Lars,<br>
<br>
Oh. I see you've set containment="true" which makes EMF think this
feature is an EReference rather than an EAttribute; hence you can only
add EObjects to it and java.lang.String isn't an EObject. You need to
remove the containment="true"<br>
<br>
<br>
Lars Vogel wrote:
<blockquote cite="mid:fse9ne$lc0$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Ed,
The compliance level for EMF and Java is set to 6.0 and I receive the
following error:
Exception in thread "main" java.lang.ClassCastException: java.lang.String
cannot be cast to org.eclipse.emf.ecore.InternalEObject
at org.eclipse.emf.ecore.util.EcoreEList.inverseAdd(EcoreEList. java:267)
at
org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
at test.Main.main(Main.java:15)
Best regards, Lars
"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com"><merks@ca.ibm.com></a> wrote in message
<a class="moz-txt-link-freetext" href="news:fse9ft$gmn$1@build.eclipse.org">news:fse9ft$gmn$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Lars,
Comments below.
Lars Vogel wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,
I read once that EMF 2.3 had autoboxing implemented.
</pre>
</blockquote>
<pre wrap="">Autoboxing is a feature of Java 5.0, so I'm not sure what it means for EMF
to implement it.
</pre>
<blockquote type="cite">
<pre wrap="">Does any know why the following doesn't work?
Best regards, Lars
Model:
package auto;
import java.lang.String;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import java.util.List;
/**
*
* @model
*/
public interface IBox extends EObject {
/**
*
* @model containment = "true"
*/
public EList<String> getNames();
}
Test code:
package test;
import auto.AutoFactory;
import auto.IBox;
import auto.impl.AutoFactoryImpl;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
AutoFactory factory = AutoFactoryImpl.eINSTANCE;
IBox box = factory.createIBox();
box.getNames().add("Moin");
}
}
</pre>
</blockquote>
<pre wrap="">What's not working? You're sure you've set source compatibility to 5.0
for the JDT's preferences and you've set the GenModel's Compliance Level
to 5.0?
</pre>
<blockquote type="cite">
<pre wrap="">
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
<br>
</body>
</html>
--------------000000000003040205030509--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Autoboxing in EMF fails [message #417849 is a reply to message #417848] |
Wed, 26 March 2008 20:00 |
|
Hi Ed,
Thank you for the quick help. Works now. Best regards, Lars
"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fse9so$kpn$3@build.eclipse.org...
Lars,
Oh. I see you've set containment="true" which makes EMF think this feature
is an EReference rather than an EAttribute; hence you can only add EObjects
to it and java.lang.String isn't an EObject. You need to remove the
containment="true"
Lars Vogel wrote:
Hi Ed,
The compliance level for EMF and Java is set to 6.0 and I receive the
following error:
Exception in thread "main" java.lang.ClassCastException: java.lang.String
cannot be cast to org.eclipse.emf.ecore.InternalEObject
at org.eclipse.emf.ecore.util.EcoreEList.inverseAdd(EcoreEList. java:267)
at
org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:318)
at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
at test.Main.main(Main.java:15)
Best regards, Lars
"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fse9ft$gmn$1@build.eclipse.org...
Lars,
Comments below.
Lars Vogel wrote:
Hi,
I read once that EMF 2.3 had autoboxing implemented.
Autoboxing is a feature of Java 5.0, so I'm not sure what it means for EMF
to implement it.
Does any know why the following doesn't work?
Best regards, Lars
Model:
package auto;
import java.lang.String;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import java.util.List;
/**
*
* @model
*/
public interface IBox extends EObject {
/**
*
* @model containment = "true"
*/
public EList<String> getNames();
}
Test code:
package test;
import auto.AutoFactory;
import auto.IBox;
import auto.impl.AutoFactoryImpl;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
AutoFactory factory = AutoFactoryImpl.eINSTANCE;
IBox box = factory.createIBox();
box.getNames().add("Moin");
}
}
What's not working? You're sure you've set source compatibility to 5.0
for the JDT's preferences and you've set the GenModel's Compliance Level
to 5.0?
|
|
|
Powered by
FUDForum. Page generated in 0.03920 seconds