“Java abreviação se” Respostas de código

Java uma linha se mais

statement ? true 	: 	false
  ^		  |	 ^			  ^
condition |   (instruction)
  		  |  If the statement:  
  		  |	is true | is false
--------------------------------------------------------------------------------
 Example:
int i = 10;

String out = i > 8 ? "Bigger than Eight!" : "Smaller than Eight!";
System.out.println(out);
TB__privi

Java abreviação se

//Clear example with good readabilty
String var = "Text";
String shortHand = (var.equals("Text") ? "Returns this if true" : "Returns this if false");

//Other example that is less readable
int var = 9;
int shortHand = var == 9 ? 1 : var++;

//Pseudo code
// CONDITION ? returns when true : returns when false
Cookie_n00b

Java abreviação se


name = ((city.getName() == null) ? "N/A" : city.getName());

Nervous Nightingale

Respostas semelhantes a “Java abreviação se”

Perguntas semelhantes a “Java abreviação se”

Mais respostas relacionadas para “Java abreviação se” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código