TC should be the right-hand operand in Java 8 Language Specification -


if @ java 8 language specification §15.26.1

  • otherwise, value of index subexpression used select component of array referred value of array reference subexpression.

this component variable; call type sc. also, let tc type of left-hand operand of assignment operator determined @ compile time. there 2 possibilities:

  • if tc primitive type, sc same tc.

the value of right-hand operand converted type of selected array component, subjected value set conversion (§5.1.13) appropriate standard value set (not extended-exponent value set), , result of conversion stored array component.

  1. it says "let tc type of left-hand operand of assignment operator", tc left operand , sc component of array , type of right operand.

so, code goes this:

int tc = 15;
int[] sc = {1,2,3,4,5};
tc = sc[0];

  1. next weird things, says "the value of right-hand operand converted type of selected array component"

execution 1: value of of right-hand operand sc[0] 1.
execution 2: 1 converted type of selected array component sc[0].
execution 3: 1 converted int.

  1. "and result of conversion stored array component"

execution 4: 1 stored in sc[0].

if follow step, code:

tc = sc[0];

is never happened, because sc[0] stored itself.

it should says :

  • otherwise, value of index subexpression used select component of array referred value of array reference subexpression.

this component variable; call type sc. also, let tc type of right-hand operand of assignment operator determined @ compile time. there 2 possibilities:

  • if tc primitive type, sc same tc.

the value of right-hand operand converted type of selected array component, subjected value set conversion (§5.1.13) appropriate standard value set (not extended-exponent value set), , result of conversion stored array component.

so code this:

int tc = 15;
int[] sc = {1,2,3,4,5};
sc[0] = tc;

would run, , value of tc stored sc[0]

my question: right?

it seems have misread context section of jls.

the section quoting starts with

if left-hand operand array access expression (§15.10.3), possibly enclosed in 1 or more pairs of parentheses

the array on left hand side, in

t[0] = 1; 

i'm not sure why think implies otherwise, , explicitly dealing assignment array elements.

the particular problem clause addressing is:

interface tc {};  class sc implements tc {};  class rc implements tc {};  tc[] tcarray = new sc[1]; tcarray[0] = new rc(); 

that code (ignoring syntax shortcuts) compiles, required fail @ runtime arraystoreexception.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -