Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8297321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:22:32+00:00 2026-06-08T15:22:32+00:00

My code runs in Java 5 and 6, but when I upgraded to Java

  • 0

My code runs in Java 5 and 6, but when I upgraded to Java 7 I get a “java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.GenericArrayType”.

For the following code:

public class A<T> {
  public Vector<Integer[]> arr;
}

System.out.println(((ParameterizedType)A.class.getField("arr").getGenericType()).getActualTypeArguments()[0]);
System.out.println(((ParameterizedType) A.class.getField("arr").getGenericType()).getActualTypeArguments()[0].getClass());

Java6 prints:

java.lang.Integer[]
class sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl

Java7 prints:

class [Ljava.lang.Integer;
class java.lang.Class

This different behavior is breaking my code which relies on generics. Can someone please help me understand why this happens and how to get GenericArrayType from Vector<Integer[]> arr?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:22:35+00:00Added an answer on June 8, 2026 at 3:22 pm

    The documentation for GenericArrayType states it represents an array type whose component type is either a parameterized type or a type variable.

    In the given example the array type is Integer[]. The component type, Integer, is neither a parameterized type nor a type variable. So your array type really should never have been represented by a GenericArrayType.

    So apparently JRE6 behavior was buggy and it got fixed. Sorry. 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code runs fine under Magento 1.6 but raises a Mage_Core_Exception (message: 'Cannot
The following code runs without any errors but doesn't actually delete anything: $update =
The following piece of code runs fine when parallelized to 4-5 threads, but starts
This code runs perfectly on Java but when I run this on Android platform,
I have written a multi threaded java code, which when runs creates 8 threads
The next code runs normally in SQLSERVER but when i change the web.config to
I tried to convert some C code to Java, but it is working slightly
This code runs well in my locally but gives file not found exception when
I have the following code: public void doJob() { MyObj s; for ( Object
This code runs OK in a pure Java application: Connection conn = null; Statement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.