java - How to call functor objects's function without invoking call method -


i have functor object:

private static func1<myevent, observable<data>> getdataonevent = new func1<myevent, observable<data>>() {     @override     public observable<data> call(myevent event) {         return apifactory.get().getdata()     } }; 

for invoking need this:

result = getdataonevent.call(someevent) 

is possible instead:

result = getdataonevent(someevent) 

like done python , javascript? maybe new version of java or library lombok?

just use,

private static observable<data> getdataonevent(myevent event) {     return apifactory.get().getdata() } 

and can call result = getdataonevent(someevent); whenever need it. can see, writing way, save more boiler code 5 letters .call on invocation side.

if func1 functional interface, can use containingclass::getdataonevent wherever func1<myevent, observable<data>> expected. can store static variable, if prefer using simple identifier getdataonevent function:

private static func1<myevent, observable<data>> getdataonevent                                               = containingclass::getdataonevent; 

then can use getdataonevent(event) call or getdataonevent refer func1 instance whenever need it.

if func1 not functional interface, can’t create function in compact form, on other hand, in case wouldn’t reasonable ask support calling arbitrary method without naming explicitly, either.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -