• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

operator precedence

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here under is a code , source is my fingers and my lack of knowledge, with an error.


Otuput:
bully.java:3: incompatibile types
found : java.lang.String
reqired: boolean
String test = "asdf" + true?"nammed":"unnamed";


Is it becaouse it might look like:

(something about "left.. from operator... comes first")
It is. Isn't it?
Thank you for helping me.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Petar Tomičić wrote:
Is it becaouse it might look like:

(something about "left.. from operator... comes first")
It is. Isn't it?



The ternery operator is pretty low on the precedence table. I think only assigments are lower. So... yes, the addition of the string and boolean is done first.

Henry
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yaa, It's related to operator precedence. String concatenation(+) is above to conditional operator(?. In String concatenation, we need two string literals. So If we use like , then it's correct.

Hope you will understand this.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the ternary operator ( ?: ) is on the second lowest place in operator precedence hierarchy and the lowest one is assignment.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yaa, It's related to operator precedence. String concatenation(+) is above to conditional operator(?. In String concatenation, we need two string literals. So If we use like , then it's correct.

Hope you will understand this.
 
Petar Thomas
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You very much mister Henry Wong. Thank You very much mister Abimaran Kugathasan. Thank You very much mister Rushikesh Sawant.


Thank you... I'll stop here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic