What Is This: [Ljava.Lang.Object;

What is this: [Ljava.lang.Object;?

[Ljava.lang.Object; is the name for Object[].class, the java.lang.Class representing the class of array of Object.

The naming scheme is documented in Class.getName():

If this class object represents a reference type that is not an array type then the binary name of the class is returned, as specified by the Java Language Specification (§13.1).

If this class object represents a primitive type or void, then the name returned is the Java language keyword corresponding to the primitive type or void.

If this class object represents a class of arrays, then the internal form of the name consists of the name of the element type preceded by one or more '[' characters representing the depth of the array nesting.
The encoding of element type names is as follows:

Element Type        Encoding
boolean Z
byte B
char C
double D
float F
int I
long J
short S
class or interface Lclassname;

Yours is the last on that list. Here are some examples:

// xxxxx varies
System.out.println(new int[0][0][7]); // [[[I@xxxxx
System.out.println(new String[4][2]); // [[Ljava.lang.String;@xxxxx
System.out.println(new boolean[256]); // [Z@xxxxx

The reason why the toString() method on arrays returns String in this format is because arrays do not @Override the method inherited from Object, which is specified as follows:

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())

Note: you can not rely on the toString() of any arbitrary object to follow the above specification, since they can (and usually do) @Override it to return something else. The more reliable way of inspecting the type of an arbitrary object is to invoke getClass() on it (a final method inherited from Object) and then reflecting on the returned Class object. Ideally, though, the API should've been designed such that reflection is not necessary (see Effective Java 2nd Edition, Item 53: Prefer interfaces to reflection).


On a more "useful" toString for arrays

java.util.Arrays provides toString overloads for primitive arrays and Object[]. There is also deepToString that you may want to use for nested arrays.

Here are some examples:

int[] nums = { 1, 2, 3 };

System.out.println(nums);
// [I@xxxxx

System.out.println(Arrays.toString(nums));
// [1, 2, 3]

int[][] table = {
{ 1, },
{ 2, 3, },
{ 4, 5, 6, },
};

System.out.println(Arrays.toString(table));
// [[I@xxxxx, [I@yyyyy, [I@zzzzz]

System.out.println(Arrays.deepToString(table));
// [[1], [2, 3], [4, 5, 6]]

There are also Arrays.equals and Arrays.deepEquals that perform array equality comparison by their elements, among many other array-related utility methods.

Related questions

  • Java Arrays.equals() returns false for two dimensional arrays. -- in-depth coverage

appendRow returns [Ljava.lang.Object;@ instead of values

Explanation:

  • The approach of using null is clearly a workaround and not a futureproof
    solution. Namely, if you want to start pasting from column 4 you
    would have to do [null,null,null,...row[0]] which is not the proper
    way to do it in my opinion.
  • I would advice you to get rid of appendRow and null since you
    want to paste the data from the second column onwards. Therefore,
    use setValues() instead.

Replace:

tracker.appendRow([null,row[0]]);

with:

tracker.getRange(tracker.getLastRow()+1,2,1,row[0].length).setValues(row);


Complete Solution:

function copy2(){
var responses = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("from");
var tracker = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("to");
var lastrow = responses.getLastRow();
var col = responses.getLastColumn();
var row = responses.getRange(lastrow, 1, 1, col).getValues();
tracker.getRange(tracker.getLastRow()+1,2,1,row[0].length).setValues(row);
}

Message saying [Ljava.lang.Object] being delivered in place of values

In your situation, is the following modification the result you expect?

From:

SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tweets").getRange("A3").setValue(obj_data.data);

To:

SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tweets").getRange("A3").setValue(JSON.stringify(obj_data.data));

Resolve Ljava.lang.Object

In order to obtain typed resultsets in JPA, you need to specify the entity type. In your example, you can use:

return entityManager.createQuery("SELECT a.title, a.created, SUBSTRING(a.content, 1, 200) FROM Article a ORDER BY a.created DESC", Article.class).setMaxResults(5).getResultList();

See java persistence docs here:

https://docs.oracle.com/javaee/7/api/javax/persistence/EntityManager.html

Specifically, the difference between createQuery(String qlString) and createQuery(String qlString, Class resultClass)

Ljava.lang.Object; cannot be cast to class ClassName

There's no reason to create a Object[] and then cast it (which won't work since Object is not a subclass of Node), just use

array = new Node[capacity];


Related Topics



Leave a reply



Submit