0
(items[position] != null) ? et.setText(items[position]) : et.setHint(position==0? "Title" : "Body");

Why i can't use first pattern? But in this way it works:

if  (items[position] != null)
            et.setText(items[position]);
                    else et.setHint(position==0? "Title" : "Body");
Jeste
  • 47
  • 9
  • 1
    `setText()`.. are void type, not allowed in terninary operator. – SatyaTNV Feb 11 '16 at 13:04
  • 1
    The ternary operator goes: `condition ? value1 : value2`, __not__ `condition ? statement1 : statement2`. The ternary operator is different from an `if` statement. – khelwood Feb 11 '16 at 13:07
  • http://stackoverflow.com/questions/35116134/issue-with-the-left-hand-side-of-an-assignment-must-be-a-variable/35116200#35116200 – Idos Feb 11 '16 at 13:09
  • The main reason you shouldn't do it, is because the readability will suffer a lot. And because Java is nice it will prevent you from doign it. To change the compiler to make this work wont be difficult in any way, but it really is no structure you should aim for. – AntiHeadshot Feb 11 '16 at 13:10

0 Answers0