Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6409

Re: Problem with generics and dynamic array copy

From Sebastian <sebastian@undisclosed.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Problem with generics and dynamic array copy
Date 2011-07-22 20:36 +0200
Organization albasani.net
Message-ID <j0cfva$cmc$1@news.albasani.net> (permalink)
References <j0cbru$289$1@news.albasani.net> <j0cc2t$289$2@news.albasani.net> <j0cf75$8pm$1@dont-email.me>

Show all headers | View raw


Am 22.07.2011 20:23, schrieb markspace:
> On 7/22/2011 10:30 AM, Sebastian wrote:
>
>>> public static final <T> T[] arraycopy( T[] src )
>>> {
>>> Class<T> componentType = src.getClass().getComponentType(); // !!!!
>
>
> RTFM. getComponentType() returns Class<?>, not Class<T>.
>
> <http://download.oracle.com/javase/6/docs/api/java/lang/Class.html#getComponentType%28%29>
>
>
> public Class<?> getComponentType()
>
> Returns the Class representing the component type of an array. If this
> class does not represent an array class this method returns null.
>

well, yes, but given that src.getClass() must give one the class object
for arrays with component type T, why is the compiler not smart enough 
to infer that the unknown class parameter in the return value of
getComponentType() must be T? As a human I can see that, that's why I
can cast to Class<T>, but I don't believe that I'm smarter than javac...

-- Sebastian

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Problem with generics and dynamic array copy Sebastian <sebastian@undisclosed.invalid> - 2011-07-22 19:26 +0200
  Re: Problem with generics and dynamic array copy Sebastian <sebastian@undisclosed.invalid> - 2011-07-22 19:30 +0200
    Re: Problem with generics and dynamic array copy markspace <-@.> - 2011-07-22 11:23 -0700
      Re: Problem with generics and dynamic array copy Sebastian <sebastian@undisclosed.invalid> - 2011-07-22 20:36 +0200
        Re: Problem with generics and dynamic array copy Robert Klemme <shortcutter@googlemail.com> - 2011-07-22 21:27 +0200
          Re: Problem with generics and dynamic array copy lewbloch <lewbloch@gmail.com> - 2011-07-22 13:33 -0700
          Re: Problem with generics and dynamic array copy Sebastian <sebastian@undisclosed.invalid> - 2011-07-22 22:37 +0200
            Re: Problem with generics and dynamic array copy lewbloch <lewbloch@gmail.com> - 2011-07-22 15:49 -0700

csiph-web