groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From OC <...@ocs.cz>
Subject Re: changing dynamically the name of classes in a source code
Date Mon, 28 Mar 2016 16:10:35 GMT
Weird... that's probably a question for Jochen on another guru. Perhaps Lists work in a special
way, different from other classes? No idea; I just have tested and found it works.

Indeed, with my own class instead of List it leads to the (completely absurd and very anti-object-oriented)
“Cannot cast object” exception.

That's precisely the terrible mess which causes Java to be one of the worst languages for
learning :(

All the best,
OC


On 28. 3. 2016, at 15:53, frenchy48 <bamade@in2p3.fr> wrote:

> Thanks for replying
> as a side note OOP appear only in chapter 8 of my book so I have to survive
> in the meantime 
> A long long time ago I used object logo ... sticking to groovy helps me to
> provide the additional codes I want to create simplistic graphics.
> 
> now back to the main point:
> when I read your example I thought "good Lord I wasn't even aware of that!
> how come?"
> then I tested .... and 
> 
> ---------------
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast
> object
> 'scrountch.geom.SFrame[frame1,0,23,300x442,layout=java.awt.BorderLayout,title=,maximized]'
> with class 'scrountch.geom.SFrame' to class 'Cadre'
> --------------
> with 
> 
> (SFrame being a groovy class of the framework)
> 
> but 
> 
> does work ....
> 
> so ???? what's the difference?
> 
> 
> OC wrote
>>> now if you have a factory that returns the proper class and you assign it
>>> to
>>> a variable typed with a subclass it won't work.
>> 
>> ===
>> 26 /tmp> &lt;w.groovy
>> class Localizeděščřžýáíí extends LinkedList { }
>> class Factory { static LinkedList list() { return new LinkedList() } }
>> 
>> Localizeděščřžýáíí ěěě=Factory.list()
>> ěěě&lt;&lt;&quot;Actually, it does work, though in Java-based language
>> it's a small miracle&quot;
>> println &quot;${ěěě.class.simpleName} contains $ěěě&quot;
>> 27 /tmp&gt; groovy w 
>> Localizeděščřžýáíí contains [Actually, it does work, though in Java-based
>> language it's a small miracle]
>> 28 /tmp> 
>> ===
> 
> 
> 
> 
> 
> -----
> member of Grumpy Old Programmers
> --
> View this message in context: http://groovy.329449.n5.nabble.com/changing-dynamically-the-name-of-classes-in-a-source-code-tp5732080p5732085.html
> Sent from the Groovy Users mailing list archive at Nabble.com.


Mime
View raw message