Vringar
Vringar

Reputation: 572

Why does casting from String[] to Object only work with a reference?

My question boils down to: Why does

Object test = {"2"};

not work while

 String[] test = {"2"};
 Object bla = test;

does?

Upvotes: 0

Views: 69

Answers (1)

Paplusc
Paplusc

Reputation: 1130

It is because the compiler thinks that {"2"} it is an array but if you declare directly with an object you have to specify it is gonna be an array too.

Upvotes: 2

Related Questions