Arrays of arbitrary dimensions / Class object for primitive types
Here's an interesting problem: is there any way to code for the creation of an n-dimensional array where n is only known at runtime (input by user, etc.)?
java.lang.reflect.Array has a newInstance method which returns an array of an arbitrary number of dimensions specified by the int[] argument, which would give me what I want. However, the other argument is a Class object representing the component type of the array. If you want to use this method to get an array of a primitive type, is it possible to get a Class object representing a primitive type?
Devil is in the detailspublic class Test2 {
public static void main(String[] args) {
Object[] myArray = new Object[10];
fillDimensionalArray(myArray, 5, 5);
public static void fillDimensionalArray(Object[] array, int dim, int size) {
if (dim==1) {
for (int i=0; i<size; i++) {
array[i] = new int[size];
for (int j=0; j<size; j++) ((int[])array)[j]=999;
} else {
for (int i=0; i<array.length; i++) {
array[i] = new Object[size];
for (int j=0; j<size; j++) {
fillDimensionalArray( (Object[]) array[i], dim - 1, size);
Similar Messages
-
Create array of arbitrary dimensions / get Class object for primitive types
Here's an interesting problem: is there any way to code for the creation of an n-dimensional array where n is only known at runtime (input by user, etc.)?
java.lang.reflect.Array has a newInstance method which returns an array of an arbitrary number of dimensions specified by the int[] argument, which would give me what I want. However, the other argument is a Class object representing the component type of the array. If you want to use this method to get an array of a primitive type, is it possible to get a Class object representing a primitive type?That doesn't help, since the whole problem is that the number of dimensions aren't known until runtime. You can't simply declare a variable of type int[][] or use an int[][] cast, since the number of []'s is variable.
The int.class construction was partly what I was looking for. This returns the array needed (assuming some read method):
int dimensions = read();
int size = read();
int[] index = new int[dimensions];
for (int i = 0; i < dimensions; i++)
index[i] = size;
Object myArray = Array.newInstance(int.class, index);The only problem is, as an Object, I can't use myArray usefully as an array. And I can't use a cast, since that requires a fixed number of dimensions. -
I am running ATG[10.1.2] app on Jboss [EAP 5.1.0 GA] I am able to open dyn/admin however when I start my app I get the below error
java.lang.LinkageError: loader constraint violation: when resolving method "atg.servlet.ServletUtil.setSessionConfNumCacheRequest(Ljavax/servlet/http/HttpServletRequest;)Ljavax/servlet/http/HttpServletRequest;" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, atg/filter/dspjsp/PageFilter, and the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) for resolved class, atg/servlet/ServletUtil, have different Class objects for the type javax/servlet/http/HttpServletRequest used in the signature
at atg.filter.dspjsp.PageFilter.doFilter(PageFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at atg.servlet.ForwardFilter.doFilter(ForwardFilter.java:263)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at atg.servlet.ErrorFilter.doFilter(ErrorFilter.java:279)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:446)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:416)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:342)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:286)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:680)
11:22:47,413 ERROR [[localhost]] Exception Processing ErrorPage[errorCode=500, location=/global/errorPage500.jsp]The supported JBoss version for 10.1.2 is JBoss EAP 5.1.2 but I don't think that your issue is caused because of this. Your issue is more of an environmental thing as you are probably getting two different versions getting loaded of class javax.servlet.http.HttpServletRequest and so correspondingly two different Class objects as the error shows. One reason for this could be if you include any server-specific libraries (in present case the Servlet API JAR which contains the class javax.servlet.http.HttpServletRequest) of a different version in the /WEB-INF/lib of your web application. Try removing it from there if so and see if that helps.
-
Get class object for primitive datatype name stored in a string
Hi,
I have an array of Strings:
String[] somePrimitives = {"int", "char", "void" };
I want to achieve the equivalent of :
for(int k = 0; k < somePrimitives.length; k++) {
Class myClass = Class.forName(somePrimitives[k]); //Wont work
We all know, we cannot do Class.forName("int") etc since "int" is not a path to
an actual class - whereas Class.forName("java.lang.Integer") will work.
Can anyone tell me how to achieve the above ?
Of course, I don't want to have numerous hardcoded checking conditions like
if(somePrimitives[k].equals("int")) return (Integer.TYPE);
thanks.1. Why couldn't java provide me a simple provision to list all available primitives and their corresponding
class mapping ? Why should I do the mapping...shouldn't the language have taken care of
its provisions ?Yes, and native compilation on the fly, dynamic modification of classes, a sensible types system, usable Number tree, quasiquotation, access to the AST of the source, getting a method based on argument types rather than parameter types, etc. etc.
2. Or even better they could have made the method
Class.getPrimitiveClass(String primitiveDatatTypeName)
as a public method. This would have solved the whole
problem with a one line piece of code. Why did they
have to make it non-public ???If you want it easy, go elsewhere.
But seriously, the reflection capabilities were tagged onto Java as it grew, and were not designed to reflect the state of the art, but as a 'just enough to get by' solution. Most of the time people don't need it, so it's not there, any you have to roll your own.
Pete -
User defined class objects for a ADF component (button,inputfield)
How do I define a user defined class object for ADF objects?
My requirement is that when I do a modification to the class object, it should get reflectected to all the instances on my page.
E.g:- I'm having class object clsInputField, and all my input fields in my pages are based on this object. So when I change clsInputField it should get reflected to all my controls based on this class object.
Please help!!!Hi Timo,
In our client server environment, we have a custom control for managing the zip code (used a Custom InputText field which extends the actual TextField) . All zip code specific validations are written in this custom class. In our application many of the pages uses this Custom component. So if any of the zipcode specific behaviour changes, we could implement this by only changing the Custom InputText field class.
We need to implement this behaviour in our ADF applications. Please advise.
Thanks,
Vishnu -
Getting the class of a primitive type or void
Hello,
Class.forName cannot be used to get the class of a primitive type or void. What does then ???
I thought of defining a class for each primitive type and override getClass() to return the required type, but getClass() is final ...
Please helpI don't understand what you mean e.g.I get the name of the primitive type at runtime and need to convert it to a class. For example, Class.forName("byte") returns byte.class. But, unfortunately, Class.forName() doesn't return classes of primitives or void.
I already solved the problem through putting ptimitive classes in a hashtable. But I was wondering if there is a simpler solution !!! -
Kindly tell me authorization object for MRP type
Hi friends,
Kind tell me what is the authorization object for MRP type in material master.
Your help is considered more important.
thanks in advance
willaimsHi Willaim,
There is no standard authorization object for MRP type.
Regards,
Alexander -
Kindly give authorization object for mrp type in material master
Hi friends,
Kind tell me what is the authorization object for MRP type in material master.
Your help is considered more important.
thanks in advance
willaimshi,
check your authorisation objects here:
Go to PFCG --> Environment (at menu bar) --> authorization objects --> Display...
Here see for MRP and MM for material managament in the tree structure...
Regards
Priyanka.P -
Authorization Object for Material Type
Hi All,
Is it possible to restrict the user from creating the material master based on Material Type. If yes then what is the authorization object for the same.
Regards
MahendraDear Mahendra,
You can definitely restrict a end-user to only particular Material Type thru Authorizations.
Authorization Object: M_MATE_MAR
This can be done thru authorization management. Consult your Basis person or follow this:
SU01 - Enter the user Id & select display button. Now click on the Roles Tab & note down the role assigned to this user Id.
Go to T-Code - PFCG - enter the Role name & select the change icon.
Click on the Authorizations tab page. & then Click on Change Authorization Data.
Now expand the menu tree of Materials Management: Master Data & further expand the menu tree of Material Master: Material Types. Now click on the change icon next to Authorization Group & select the required Material Type that you want to authorize the end-user.
This is how you can give authorizations only for a particular Material Type.
Hope this helps.. .
Give point if useful...
Thanks,
Jignesh Mehta
Mumbai -
Authorisation object for inspection type
Dear QM consultants,
We are developing one Z program where plant, inspection lot origin and inspection type are main input fields. We want to add authorisation object based on these inputs. I checked for M_BEST_WRK for plant and Q_INSPTYPE for inspection type. Object for plant is working fine but we are unable to restrict based on inspection type since Q_INSPTYPE does not have any activity field associated with it.
Has anybody come across such issue? Whether objects taken by me are correct, if not can anybody guide me what are the authorisation objects to be taken.
Thanks in advance.
Best Regards,
Anand RaoHi
Create your own autherization group with SU21
This will bring better control
Regards
Sujit -
Authorization Object For Order Type in Tcode KO88
Dear Sir,
In Tcode KO88 , we want that an users must be able to use only a specific type "Order Type" . But we do not know which is the authorization object for this .
I look forward for the kind help from SAP Expert as how can we put restriction based on "Order Type" in Tcode KO88 .
Regards
B V Mittalhi,
check your authorisation objects here:
Go to PFCG --> Environment (at menu bar) --> authorization objects --> Display...
Here see for MRP and MM for material managament in the tree structure...
Regards
Priyanka.P -
Collection framework for primitive types
Hi,
I am developing an open source collection library for primitive data types. It has just moved out of beta and into production development, menaing that from now on, the API is backwards compatible.
The sources, binaries, and docs can be downloaded from: http://pcj.sourceforge.net.
Comments and suggestions are always welcome!
Regards,
Søren BakThanks, I'm downloading it now.
-
Why is the Integer wrapper class object and primitive object equal ?
This is my code :
package obectorientation;
public class oo3 {
public static void main(String[] args) {
int x=1; float y=1.0F;
int x1=1;
Integer y1= new Integer(1);
if(x1==y1)
System.out.println("Equal");
else
System.out.println("NOT Equal");
O/P : EqualMy question is why are x1 and y1 equal ? Won't y1 be a different object and x1 just a primitive variable ?
Thanks in Advance.Specifically, it's because y1 gets unboxed before the comparison. What's really happening is effectively: if ( x1 == y1.intValue() )
-
Authorization Object for Storage Type
Hi Experts,
We want to restrict the goods movement based on storage type. Does anybody know what authorization object we can use to implement that?
Any help is greatly appreciated.
Thanks,
KhanHi,
At PFCG, go to authorization profile you want to restrict, look for M_MSEG_LGO Authorization Object, at the storage location field assign it. If you only want to restrict it for few user use, remove those from unauthorized user profile.
Hope it might help. -
Authorization issue object for material type !
Dear,
All.
In my client system there are 10 users now my client want to restrict the access of various transaction on material type level to each user.
(example if there is user mm.agt the system should allow him access for only raw material type , in various transaction )
Please help me.
Regards.
Hassan NaveedHello Naveed,
If you are talking about restriction of material types under MC.1 & MC.9 , M_IS_MTART (ROH - Raw materials) is the object where you can restrict material types.
If this is not the case,please elaborate your question with more info.
Rgds,
Gadde.
Maybe you are looking for
-
How will i know if a virus,malware or spyware is d...
i hve scan my comp and it wont finish scanning 1 program files un-scaned and alcohol120 program files. i'm a bit woried about the privacy of our video call.. my wifes brother warned us of some virus that is includen on some sofwres that you might dow
-
I wanted to make a partition with bootcamp, but I couldn't, so I upgraded to Mavericks and it worked!, but now iPhoto, App Store, Photo Booth many others don't work.. IPhoto says that the version can not longer be used on Mac OS X 10.9, and that I ne
-
HT4623 I cannot update to iOS 8, please help!
I cannot update to iOS 8 because i get the not enough storage error, even though i have 4.6GB free, according to usage. What can i do? Except using itunes because i'm on holiday and i do not have acces to a computer.
-
Message queues and expiry *HELP*
My problem is hopefully a simple one to overcome. Without going totally in depth, i have a Server program that creates JMS Object messages and sends them off to a message Queue. Then i have another program, a client, that recieves and processes the o
-
When selecting print a blank screen appears (see photo)
Dear All, When I click on the "print" button in Acrobat Reader X , i get the "print" window but all buttons are blank and only the page preview is shown. I rolled this version out on 1200 machines and some of them have this issue. The version is 10.0