java


What does this syntax mean in Java? [duplicate]


While hunting through some code I came across the arrow operator, what exactly does it do? I thought Java did not have an arrow operator.
return (Collection<Car>) CollectionUtils.select(listOfCars, (arg0) -> {
return Car.SEDAN == ((Car)arg0).getStyle();
});
Details: Java 6, Apache Commons Collection, IntelliJ 12
Update/Answer: It turns out that IntelliJ 12 supports Java 8, which supports lambdas, and is "folding" Predicates and displaying them as lambdas. Below is the "un-folded" code.
return (Collection<Car>) CollectionUtils.select(listOfCars, new Predicate() {
public boolean evaluate(Object arg0) {
return Car.SEDAN == ((Car)arg0).getStyle();
}
});
That's part of the syntax of the new lambda expressions, to be introduced in Java 8. There are a couple of online tutorials to get the hang of it, here's a link to one. Basically, the -> separates the parameters (left-side) from the actual expression (right side).
I believe, this arrow exists because of your IDE. IntelliJ IDEA does such thing with some code. This is called code folding. You can click at the arrow to expand it.
It's a lambda expression.
It means that, from the listOfCars, arg0 is one of the items of that list.
With that item he is going to do, hence the ->, whatever is inside of the brackets.
In this example, he's going to return a list of cars that fit the condition
Car.SEDAN == ((Car)arg0).getStyle();

Related Links

how to modify the value of a primitive data passed to a C++ routine using Java and JNI?
Java: test System output including “new lines” with assertEquals
How to ignore ' ' in Xpath?
Casting a type in a data structure
Spring Boot EnableCaching and Cacheable annotation not working
FATAL EXCEPTION: main NoSuchMethodError for VideoView.setOnPreparedListener() [duplicate]
Using SWIG to wrap c++ to java UnsatisfiedLinkError: HeaderJNI.new_Test()J
Java accessing object throught array
JavaFX ScrollPane setVvalue() not working as intended
Efficient handling of mouse clicks
Right syntax for concat on derby
Break 2 loops if condition satisfied in Java [duplicate]
Simple Java currency converter errors
Vert.x Json.decodeValue list
Auditing with spring-data-mongodb
Unable to save screenshot at desired location

Categories

HOME
yii2
vbscript
listview
isabelle
server
cmd
installshield
swagger-ui
qore
android-youtube-api
fallback
iron-router
carthage
apache-metamodel
solaris-10
introduction
tar
intel-pin
uninstall
spring-mybatis
minitab
large-file-upload
google-cloud-endpoints-v2
ioio
caret
wallpaper
hexo
android-ble
x11-forwarding
swift3.0.2
twitch
webix-treetable
unobtrusive-validation
dynamic-reports
termination
paxos
celery-task
domain-model
lowpass-filter
sqlclient
lift-json
typed-lambda-calculus
sybase-asa
windows-mobile-6.5
capacity
quartz-composer
url-pattern
home-directory
trash
google-web-starter-kit
whois
pervasive-sql
metaclass
python-3.2
qdialog
fouc
content-length
generic-programming
unity3d-gui
unity5.2.3
rake-task
gwidgets
websocket4net
mechanize-ruby
balanced-payments
floating-point-precision
farseer
aqtime
coverflow
tws
hungarian-algorithm
clipper
trusted
reddot
xtype
pyinotify
lpeg
database-management
javap
anti-piracy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App