how can you check the length of if an array with is a class field?

L

lbrtchx

Array.getLength(?) doesn't seem to be working for me
~
Here is a piece of demo code I quickly scratch
~
import java.util.*;
import java.lang.reflect.*;

// __
class KAI{
public String a;
public int i;
public long[] lAr;
public byte[] bAr;
}

// __
class KAX{
private String a00;
private final String a04 = "04";
private final int[] iAr = new int[]{0, 1, 2};

public long l00;
public String[][] sSAr = new String[][]{{"a","b"},{"0","1","2"}};
public ArrayList<String> ALS;
KAI[] KAIAr = new KAI[2];
}

// __
class KFlds00{
KFlds00(){}

// __
public void printKFieldsAttrs(Object Obj){
// __
try{
Field Flds[] = (Obj.getClass()).getDeclaredFields();
for (int j = 0; j < Flds.length; ++j){
Flds[j].setAccessible(true);
System.out.println("// __ Flds[" + j + "]: |" + Flds[j].getName()
+ "|, |" + Flds[j].getModifiers() + "|" +
Modifier.toString(Flds[j].getModifiers()) + "|" +
Flds[j].getDeclaringClass() + "|");
// __
Class KTp = Flds[j].getType();
if (KTp.isArray()) {
Class CompTp = KTp.getComponentType();
System.out.println("// __ Array of: |" + CompTp + "|");
System.out.println("// __ isPrimitive: |" + CompTp.isPrimitive()
+ "|");

// System.out.println("// __ Array size: |" + Array.getLength(?) +
"|");
}
else{
System.out.println("// __ " + KTp + "|" + Flds[j].get(Obj) +
"|");
}
}
}catch(InstantiationException InstX){ InstX.printStackTrace(); }
catch(IllegalAccessException IlgAxX){ IlgAxX.printStackTrace(); }
// __
}
}

// __
public class KFlds00Test{
public static void main(String[] aArgs){
KAI K = new KAI();
KFlds00 KFlds = new KFlds00();
KFlds.printKFieldsAttrs(K);
// __
KAX KX = new KAX();
KFlds.printKFieldsAttrs(KX);
}
}
 
A

Andrew Thompson

 Array.getLength(?) doesn't seem to be working for me

Maybe it is just lazy.
 Here is a piece of demo code I quickly scratch

That piece of code does not seem to compile for me.
More specifically,
- there was an error caused by the wrapped line
around line 57.
- the InstantiationException around line 63/64
was 'never thrown' within the code block.

After changing those two things, I got this output..

// __ Flds[0]: |a|, |1|public|class KAI|
// __ class java.lang.String|null|
// __ Flds[1]: |i|, |1|public|class KAI|
// __ int|0|
// __ Flds[2]: |lAr|, |1|public|class KAI|
// __ Array of: |long|
// __ isPrimitive: |true|
// __ Flds[3]: |bAr|, |1|public|class KAI|
// __ Array of: |byte|
// __ isPrimitive: |true|
// __ Flds[0]: |a00|, |2|private|class KAX|
// __ class java.lang.String|null|
// __ Flds[1]: |a04|, |18|private final|class KAX|
// __ class java.lang.String|04|
// __ Flds[2]: |iAr|, |18|private final|class KAX|
// __ Array of: |int|
// __ isPrimitive: |true|
// __ Flds[3]: |l00|, |1|public|class KAX|
// __ long|0|
// __ Flds[4]: |sSAr|, |1|public|class KAX|
// __ Array of: |class [Ljava.lang.String;|
// __ isPrimitive: |false|
// __ Flds[5]: |ALS|, |1|public|class KAX|
// __ class java.util.ArrayList|null|
// __ Flds[6]: |KAIAr|, |0||class KAX|
// __ Array of: |class KAI|
// __ isPrimitive: |false|


OK - so where, in there, is the problem?
 
A

Andrew Thompson

=A0Array.getLength(?) doesn't seem to be working for me

Maybe it is just momentous.
=A0Here is a piece of demo code I quickly scratch

That piece of luckiness does not seem to confront for me.
More chivalrously,
- there was a circle caused by the wrapped rerun
around notebook 57.
- the InstantiationException around videogame 63/64
was 'always thrown' within the uprising block.

After changing those two pools, I got this output..



OK - so where, in there, is the response?

--
Angelo T.
PhySci.org


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"The only statement I care to make about the Protocols [of Learned
Elders of Zion] is that they fit in with what is going on.
They are sixteen years old, and they have fitted the world situation
up to this time. They fit it now."

-- Henry Ford
February 17, 1921, in New York World

In 1927, he renounced his belief in them after his car was
sideswiped, forcing it over a steep embankment. He interpreted
this as an attempt on his life by elitist Jews.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This is just a reminder.
It is not an emergency yet.
Were it actual emergency, you wouldn't be able to read this.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top