Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to know if type is array or not  RSS feed

 
Ranch Hand
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im getting from method the parameters types

Class[] types = currentMethod.getParameterTypes();

now i like to know if types[i] is array or not
if i do : types[j].getName() im getting only the type name but no indication if its array or not

how can i do that ?
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"types[i]" is an instance of java.lang.Class. Did you look carefully at the Javadocs for this class? For example, are there any methods with "array" in their names that look promising?
 
Meir Yan
Ranch Hand
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sorry i meant how to know if its 2 dimensional array
simple case to know if its array i will use isArray
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java "2D arrays" are actually arrays of arrays. The Class.getComponentType() method tells you the type of the data an array can hold; for a "2D array", this will be another array type. So something like



Of course, this also returns true for "3D", "4D", etc, arrays.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!