Sadly – no. The closest you can do is:
int y = (x != null) ? x : -1;
Of course, you can wrap this up in library methods if you feel the need to (it’s unlikely to cut down on length much), but at the syntax level there isn’t anything more succinct available.
More Related Contents:
- What’s the C++ idiom equivalent to the Java static block?
- Java equivalent to C++ arrow [closed]
- What's the c++ version of this java map code [closed]
- What is a shell script, makefile and ant file [closed]
- Run c/java/python with PHP? [duplicate]
- java vs C++ in pre and post increment
- What is the difference between Java Garbage collection and C++ object destruction? [closed]
- How to create a Java ArrayList in C
- Is there a way to simulate the C++ ‘friend’ concept in Java?
- What is the equivalent of the Java BigDecimal class in C#?
- How to call Java functions from C++?
- Java’s final vs. C++’s const
- Missing return statement in a non-void method compiles
- Selenium WebDriver: Wait for complex page with JavaScript to load
- Why are strings immutable in many programming languages? [duplicate]
- Tool to convert java to c# code [closed]
- Why hypot() function is so slow?
- How to compile dynamic library for a JNI application on linux?
- Technical reasons behind formatting when incrementing by 1 in a ‘for’ loop?
- How to call C++ from Java?
- fastest (low latency) method for Inter Process Communication between Java and C/C++
- Class method and variable with same name, compile error in C++ not in Java?
- How do I get the intersection between two arrays as a new array?
- Calling virtual method in base class constructor
- Algorithm – How to delete duplicate elements in a list efficiently?
- How do I convert jstring to wchar_t *
- Persisting sha256 hash objects?
- Interview question – Search in sorted array X for index i such that X[i] = i
- Finding the median value of an array?
- C++ ifstream.getline() significantly slower than Java’s BufferedReader.readLine()?