• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Are developers actually using Optional?

 
Ranch Hand
Posts: 62
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. My questions is about if developers today, in the everyday work, use Optional instead of null.
I ask it because I spend almost four years without working in a formal way as developer for a company and I don't know if people use this features of Java 8.

Before I was woking in average 2 years with Java 4, 6 and 7 and it's like there has been a lot of water under the bridge so far.

Thanks for your opinion!
 
Master Rancher
Posts: 260
12
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My professional Java experience is still very limited, but I can see the use of Optional. Personally, I'd use it.
 
Saloon Keeper
Posts: 21133
134
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be using it in new code, if I wasn't using other languages lately.

A lot of Java apps by now are legacy apps. Hardly as much so as COBOL, but enough that many of them predate the modern niceties.
 
Marshal
Posts: 14053
234
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Totally unscientific wild-a$$ guess: No, most developers don't use Optional. I would guess more than 50% of Java developers being paid to write Java code will give you a blank stare back if you ask them that question.

Edit: I may sound very cynical but I'm guessing the above because most code I have seen in the past few years since Java 8 introduced Optional has either NOT been written to Java 8 or they are still returning null values from methods all over the place. They don't even return empty collections when they should. I see this kind of code all the time:

Sorry, but you can't help being cynical about Optional if programmers don't even have the common sense to design APIs that return at least an empty collection instead of null.
 
Pablo Napoli
Ranch Hand
Posts: 62
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for your replies so far. And Junilu Lacar about you said, I agree haha. But I wasn't sure really and these are the big differences between we can find in a book and on the other hand, in real life.

I will attach a pic about what the book says about it (OCP Study guide).

Said that, I'm very grateful to have these books with me, They're the best I found.

Anyway I'd like to read opinions where people say if either this feature is a good tool, o not, and why. Beause maybe it's a very good feaure that it's not implemented because the low level coding of programmers.

Let me say, in my opinion (I discovered it 2hs ago) It's not so intuitive. So to understand how it works you should look the class in deep. So I prefer code more readable that so technical.
20191007_184448.jpg
[Thumbnail for 20191007_184448.jpg]
 
Marshal
Posts: 65814
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pablo Napoli wrote:. . . the book . . . (OCP Study guide). . . .

Please supply more details, so we can find the correct book and page.
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Junilu, I can't speak for "all developers" or even a small subset of them. But I have this application which was originally written nearly 10 years ago and which I use almost every day. It's still a work in progress but obviously it was written long before Optional existed. As new Java features come along I try to use them in the app, for example I changed it to use try-with-resources throughout. (About 60 changes.) And recently I decided to use Optional in one of my application updates, where null-handling used to be there. There's a lot more scope for using Optional, obviously, as there are several hundred classes in the application. So when I get some time I might try to change more of the null-handling code to use Optional instead -- there are still weird situations which very rarely cause NullPointerException.
 
Pablo Napoli
Ranch Hand
Posts: 62
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ritchie. The book is OCP study guide of Jeanne and Scott and the picture is from the page 185.
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!