It kinda depends on how the device.eventStream() method is defined, but I imagine the code looks a little like this:
// this is a field
SparkEvent?[] events := SparkEvent?[null]
...
// a statement that passes an event handler function that sets the first item in the list
eventStream := device.eventStream |SparkEvent e| { events[0] = e }
But I'd imagine it'd be better to define a list that takes non-null items and just add the event to the list:
It is using Consumer Interface that I'm not familiar!
SlimerDudeSun 22 Oct 2017
I can't make this work.
Without an error message, stacktrace, or the fully qualified names of the classes involved, I can't really suggest much.
But, assuming you mean the new java.util.function.Consumer interface of Java 8, then unfortunately I don't think you can use it in Fantom...
For if you try to create an implementation in Fantom, then you get a compilation error:
class MyConsumer : Consumer {
override Void accept(Obj? obj) { }
override Consumer? andThen(Consumer? arg) { null }
}
Class 'MyConsumer' must be abstract since it inherits but doesn't override
'[java]java.util.function::Consumer.lambda$andThen$0'
lambda$andThen$0() seems to be a synthetic method related to the new Java8 default methods. But due to it being an illegal method name, it can't be overridden.
So you may need to drop into Java to use that method.
I don't know if Brian, or anyone else, can give any insight in to what these methods are and how they may be used / implemented in Fantom. My concern is that, given Java8 will continue to become more wide spread, these default methods will only become more popular.
brianSun 22 Oct 2017
You probably aren't going to be use some of the Java 8 language features in Fantom FFI since it was designed before Java 8 came out.
But you can still pretty easily use integrate with anything in Java with native methods - just requires dropping down to Java directly and creating an appropriate wrappers. See docLang::Natives
dalMon 23 Oct 2017
Thanks for help, you are right, this library is using all new Java 8 features. It looks for now I will not need that method! I will check Natives as well down the road I will rewrite directly in Fantom as practice!
dal Fri 20 Oct 2017
Hi
I'm new in Fantom and wrapping up next java libraries in pod:
https://github.com/grantwest/SparkJ
There is portion of Java I'm not sure how to write down equivalent in Fantom!
Any help is appreciate!
SlimerDude Fri 20 Oct 2017
Hi
dal
!It kinda depends on how the
device.eventStream()
method is defined, but I imagine the code looks a little like this:But I'd imagine it'd be better to define a list that takes non-null items and just add the event to the list:
You may also be able to use an it-block for the event handler:
dal Sat 21 Oct 2017
Hi
Thanks for replay!
I can't make this work.
This is original method!
It is using Consumer Interface that I'm not familiar!
SlimerDude Sun 22 Oct 2017
Without an error message, stacktrace, or the fully qualified names of the classes involved, I can't really suggest much.
But, assuming you mean the new java.util.function.Consumer interface of Java 8, then unfortunately I don't think you can use it in Fantom...
For if you try to create an implementation in Fantom, then you get a compilation error:
lambda$andThen$0()
seems to be a synthetic method related to the new Java8default
methods. But due to it being an illegal method name, it can't be overridden.So you may need to drop into Java to use that method.
I don't know if Brian, or anyone else, can give any insight in to what these methods are and how they may be used / implemented in Fantom. My concern is that, given Java8 will continue to become more wide spread, these
default
methods will only become more popular.brian Sun 22 Oct 2017
You probably aren't going to be use some of the Java 8 language features in Fantom FFI since it was designed before Java 8 came out.
But you can still pretty easily use integrate with anything in Java with native methods - just requires dropping down to Java directly and creating an appropriate wrappers. See docLang::Natives
dal Mon 23 Oct 2017
Thanks for help, you are right, this library is using all new Java 8 features. It looks for now I will not need that method! I will check Natives as well down the road I will rewrite directly in Fantom as practice!