This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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

Operator self test question and Flow Control doubt.

 
Ranch Hand
Posts: 49
Eclipse IDE Spring Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings there people

Here I come again with 2 doubts this time, one from a self test and another from an explanation in a chapter I don't understand >_< !

Let's go by parts:

==> Self test questions (Regarding operators this time but it has nothing to do with operators , more like enums )



I don't know there how exactly for works. I believe while its checking the enum (it returns an array as said), then I believe declared Days type variable "d" , takes F value once it finds it on the enum, assigning it to d2 variable.

When comes to ternary operator , ¿ isn't it comparing something like : Days.TH = Days.F ? Of course, due answer I am wrong, but I don't know why. (Probably in mistaken with reasoning)


====

Second part, the doubt about an explanation regarding flow control.

Reading about switch statement and case .

Here what it says:



Wow! how is so? Aren't both vars final int? . So then? (Or its due b takes value 2 in another line instead when declared? )

=======

That's all.

Thanks in advance for the answers ^_^
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

For the Enum question, on line 8, there is a "if(d.equals(Days.F)) break".
Because of this break, it will not go to line 9, where d2 will become Days.F.
So d2 retains its older value Days.TH. For this reason, the ternary operator's will return true, that is, d1(Days.TH) == d2(Days.TH). Hence the result "same old".
Hope this makes sense!

Cheers
Mahesh
 
Mahesh Murugaiyan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

While exlploring your second question on final, i was little puzzled. My understanding goes like this:
1. final variables can be assigned value only once. So, the lines 8,9 looks good to me.
2. However, "case" doesnt seem to accept a final variable which was not initialized during declaration. This seems odd to me!





Cheers
Mahesh
 
David Samer
Ranch Hand
Posts: 49
Eclipse IDE Spring Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mahesh Mak wrote:Hi David,

For the Enum question, on line 8, there is a "if(d.equals(Days.F)) break".
Because of this break, it will not go to line 9, where d2 will become Days.F.
So d2 retains its older value Days.TH. For this reason, the ternary operator's will return true, that is, d1(Days.TH) == d2(Days.TH). Hence the result "same old".
Hope this makes sense!

Cheers
Mahesh



Oh my... Can you believe I haven't seen that break there until you said it? oh hell... (and used = instead == ) *face palm* .

Thanks Mahesh

Regarding second question, I'm also confused too thinking the same, I do see line 8 and line 9 perfectly good there!

Let's hope someone can help us clarifying it
 
We can walk to school together. And we can both read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!