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 1062371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:36:58+00:00 2026-05-16T18:36:58+00:00

Today i was writing some heavy reflection-using code, and i came across this behavior

  • 0

Today i was writing some heavy reflection-using code, and i came across this behavior i can’t explain: why does

Type[] types = ((ParameterizedType)m.getGenericReturnType()).getActualTypeArguments();
Class[] c = (Class[])types;

Throw a ClassCastException, when iterating over that same array and casting every single element, i.e.

for(Type t : types) {
    Class c = (Class)t;
}

succeeds?

I mean, if the casting of a single element to another class is possible, why isn’t the casting between arrays of the same types possible as well?

There probably is a reason, but i can’t seem to find one…

  • 1 1 Answer
  • 2 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-05-16T18:36:59+00:00Added an answer on May 16, 2026 at 6:36 pm

    You can’t cast a Type[] to a Class[] because a Type[] is not a Class[]. It may sound trivial, but that’s all there is to it.

    If you could cast a Type[] to a Class[], what would you expect to happen when one of its elements was a Type that isn’t a Class (a ParameterizedType for example)?

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

Sidebar

Related Questions

When writing some rspec today, I came across some unexpected behavior with comparing Date
Today I was writing some C code to sort an array of structs using
So I was writing some code today that basically looks like this: string returnString
Today while writing some Visual C++ code I have come across something which has
So I was writing some queries today and was using top 10 on a
I was writing some code today and something was not working as I expected.
Today I had to fix some older VB.NET 1.0 code which is using threads.
In writing some code today, I have happened upon a circumstance that has caused
Today while I was writing some code for two methods that shows and hides
I was writing some code today and was mid line when I alt-tabbed away

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.