Author Topic: Why isn't this allowed?  (Read 3429 times)

Sang-drax

  • You created me, friend, you created me.
  • Jackass IV
  • Posts: 282
  • Karma: +10/-10
    • http://strandmark.com
Why isn't this allowed?
« on: September 05, 2005, 09:19:18 AM »
Consider this example of valid code:
 
Code: [Select]
class Test {
E[] array;

Test() {
array = (E[]) new Object[100];
}
}

What is the reason that the following isn't allowed?
Code: [Select]
array = new E[100];

It seems stupid that this isn't allowed because the original code is unelegant and will generate a warning. It is also a needed construction in a  lot of containers.
I don't see any reason why the  'new E'-notation shouldn't be allowed. It doesn't create any E objects, so E doesn't have to be a known type.

I've asked my lecturer, but she(!) doesn't have an answer (yet -- she said she'd think about it).

salvelinus

  • Founders
  • Posts: 523
  • Karma: +30/-12
Why isn't this allowed?
« Reply #1 on: September 09, 2005, 07:13:54 AM »
It is allowed for those with the rank of Java Master.
Go with the bad joke theory - RoD

aran

  • the capital of djibouti is djibouti
  • Jackass III
  • Posts: 110
  • Karma: +12/-3
Why isn't this allowed?
« Reply #2 on: December 31, 2005, 04:24:41 PM »
...I had no idea you could even do function templates in java!

Ya learn something new every day.
this apparatus must be unearthed.