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

NullPointerException, simple mistake? [duplicate]
Using loop to perform actionPerformed( on click button)
Resizing, flushing and closing ByteBuffer
Better way to read nextLine [duplicate]
View's Properties not changing with Property Animation
What does the question mark mean in Comparable<?>
URLFetchServiceStreamHandler$Connection cannot be cast to HttpsURLConnection
Build an in-memory local database based on an existing database and triggers [duplicate]
New tab in a jsf
Different ways to access database in Java
Getting contents of webpage in a string in Java (similar to php's file_get_contents())
How to get a whole bucket by hashcode for a Map key or Hashset?
Use rxjava2 to loop through an arraylist
DynamoDB query with expression filter
Groupping results based on fields - Lucene
Proguard interface inner class cannot access after process

Categories

HOME
keras
reserved
mfc
appx
maven-3
amortized-analysis
jsrender
v8
ezpublish
django-imagekit
constraint-programming
ssl-client-authentication
mapserver
ibm-odm
graphlab
pc
propel
shared-hosting
dbext
sylius
claims-based-identity
wijmo
pepper
poltergeist
fgetcsv
fifo
c++-amp
tasklet
instant-messaging
karaf
geopositioning
qwerty
sqlite2
awt
elmah
skeleton-css-boilerplate
dotcover
chain-builder
zip4j
qsslsocket
nstextview
forever
sqlclient
mediaelement
time-and-attendance
url-pattern
static-ip-address
asp.net-4.5
qpid
gstreamer-0.10
multiple-regression
persist
pagerank
ptrace
cisco-ios
android-nested-fragment
issuu
heisenbug
marmalade
resty-gwt
gnu-smalltalk
access-rights
limejs
html-editor
type-equivalence
libstdc++
isnullorempty
gil
bigcouch
custom-backend
transactionscope
hirefire
netbeans-7.1
disclosure
mysql-error-1005
cxxtest
modelstate
thunderbird-lightning
eqatec
ubuntu-9.04
windows-live-messenger
ajax-forms
document-conversion

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App