This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Tutorial about List Interface. Question  RSS feed

 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Do you know what the "val == null" flow control line mean? It is not related to the iteration of the list, what kind of value is "E val" suppose to be?
Studying for the OCP that's why i need to know all these details.

Thanks in advance.
The following bit of code has been taken from http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html
The line of code I do not get, is the one commented out just to highlight the line within the code.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Widelec wrote:Do you know what the "val == null" flow control line mean? It is not related to the iteration of the list, what kind of value is "E val" suppose to be?

Well, in the particular case you show, it's trying to find the element to replace. There's nothing in the rules that says a List can't contain null elements, and using equals() to check whether an object equals null doesn't make sense, because, in order to call the method, the object can't be null (and besides, you'll get a NullPointerException).

HIH

Winston
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch.

Do you know what the "val == null" flow control line mean? It is not related to the iteration of the list, what kind of value is "E val" suppose to be?


I believe you are new to Java language? Is that correct?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Widelec wrote:what kind of value is "E val" suppose to be?


http://docs.oracle.com/javase/tutorial/java/generics/
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!