|
|
|
|
Re: [Xtend2] floats [message #758149 is a reply to message #753849] |
Tue, 22 November 2011 07:08 |
Hauke Fuhrmann Messages: 333 Registered: July 2009 |
Senior Member |
|
|
Am 29.10.2011 14:48, schrieb Meinte Boersma:
> Well, decimals are included since the JVM type's available. There's just
> not a literal for it.
Maybe it would help a lot if it were possible to do infix operator
overloading also by extension methods. I.e. I understand so far you have
to define a method for the class you want to overload, e.g.
class Float{
public Float _operator_multiply(final Float other){
return this * other;
}
}
However, we cannot change the basic datatype classes, so it would be
nice I could simply write extensions like
class FloatExtensions{
public Float _operator_multiply(final Float e1, final Float e2){
return e1 * e2;
}
}
Which I then can use in my Xtend simply the same:
@Inject
extension FloatExtension
def function(Float a, Float b){
return a._operator_multiply(b)
}
Hence, it would be nice if in this case operator overloading would work
such I could write a * b instead.
Is this a proper feature request or are there arguments against?
Cheers,
Hauke
|
|
|
|
Re: [Xtend2] floats [message #758322 is a reply to message #758149] |
Tue, 22 November 2011 18:05 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi,
if you use the proper naming scheme (operator_multiply instead of
_operator_multiply) everything works.
@Inject
extension Floats
def doSomething(float a, float b) {
a * b
}
def client(Float a, Float b) {
a * b
}
==
public class Floats {
public float operator_multiply(float a, float b) {
return a * b;
}
}
Regards,
Sebastian
--
Need professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
On Tue, 22 Nov 2011 08:08:46 +0100, Hauke Fuhrmann
<hauke.fuhrmann@funkwerk-it.com> wrote:
> Am 29.10.2011 14:48, schrieb Meinte Boersma:
>> Well, decimals are included since the JVM type's available. There's just
>> not a literal for it.
>
> Maybe it would help a lot if it were possible to do infix operator
> overloading also by extension methods. I.e. I understand so far you have
> to define a method for the class you want to overload, e.g.
>
> class Float{
> public Float _operator_multiply(final Float other){
> return this * other;
> }
> }
>
> However, we cannot change the basic datatype classes, so it would be
> nice I could simply write extensions like
>
> class FloatExtensions{
> public Float _operator_multiply(final Float e1, final Float e2){
> return e1 * e2;
> }
> }
>
> Which I then can use in my Xtend simply the same:
>
> @Inject
> extension FloatExtension
>
> def function(Float a, Float b){
> return a._operator_multiply(b)
> }
>
> Hence, it would be nice if in this case operator overloading would work
> such I could write a * b instead.
>
> Is this a proper feature request or are there arguments against?
>
> Cheers,
> Hauke
|
|
|
Powered by
FUDForum. Page generated in 0.03918 seconds