primitive

Is an array a primitive type or an object (or something else entirely)?

谁说胖子不能爱 提交于 2019-11-26 01:58:39
问题 The question is basically self-explanatory. I haven\'t been able to find an API for arrays (other than this Arrays, but this just defines a bunch of static helper functions for dealing with actual arrays). If there is no class for it, this seems to suggest that an array can\'t be an Object . However, the fact that an array has public fields like length and methods that it can invoke like .equals() and .clone() seem to suggest (very strongly) the complete opposite. What is the explanation for

Java: Integer equals vs. ==

狂风中的少年 提交于 2019-11-26 01:19:23
问题 As of Java 1.5, you can pretty much interchange Integer with int in many situations. However, I found a potential defect in my code that surprised me a bit. The following code: Integer cdiCt = ...; Integer cdsCt = ...; ... if (cdiCt != null && cdsCt != null && cdiCt != cdsCt) mismatch = true; appeared to be incorrectly setting mismatch when the values were equal, although I can\'t determine under what circumstances. I set a breakpoint in Eclipse and saw that the Integer values were both 137,

What's the difference between primitive and reference types?

ⅰ亾dé卋堺 提交于 2019-11-26 00:59:27
问题 This is a past exam question and I was wondering what a primitive type and reference type are first off? With an array I know the a reference type is where the array is composed of objects or variables, but a primitive type is where you would create the array with just int or strings. (right?) How do you think you would answer the question on the test and be given good credit? Without really referring directly to an primitive ARRAY type... Is there a way to do it without that? Or do you think

In Java, is the result of the addition of two chars an int or a char?

感情迁移 提交于 2019-11-26 00:20:48
问题 When adding \'a\' + \'b\' it produces 195. Is the output datatype char or int ? 回答1: The result of adding Java chars, shorts, or bytes is an int : Java Language Specification on Binary Numeric Promotion: If any of the operands is of a reference type, unboxing conversion (§5.1.8) is performed. Then: If either operand is of type double, the other is converted to double. Otherwise, if either operand is of type float, the other is converted to float. Otherwise, if either operand is of type long,

Why is typeof null “object”?

大兔子大兔子 提交于 2019-11-25 22:45:05
问题 I\'m reading \'Professional Javascript for Web Developers\' Chapter 4 and it tells me that the five types of primitives are: undefined, null, boolean, number and string. If null is a primitive, why does typeof(null) return \"object\" ? Wouldn\'t that mean that null is passed by reference (I\'m assuming here all objects are passed by reference), hence making it NOT a primitive? 回答1: From the MDN page about the behaviour of the typeof operator: null // This stands since the beginning of

Why don't Java Generics support primitive types?

落花浮王杯 提交于 2019-11-25 22:19:00
问题 Why do generics in Java work with classes but not with primitive types? For example, this works fine: List<Integer> foo = new ArrayList<Integer>(); but this is not allowed: List<int> bar = new ArrayList<int>(); 回答1: Generics in Java are an entirely compile-time construct - the compiler turns all generic uses into casts to the right type. This is to maintain backwards compatibility with previous JVM runtimes. This: List<ClassA> list = new ArrayList<ClassA>(); list.add(new ClassA()); ClassA a =