primitive

Comparing Character, Integer and similar types in Java: Use equals or ==?

蓝咒 提交于 2019-12-12 07:26:29
问题 I wanted to make sure about something in Java: If I have a Character or an Integer or a Long and those sort of things, should I use equals or is == sufficient? I know that with strings there are no guarantees that there is only one instance of each unique string, but I'm not sure about other boxed types. My intuition is to use equals, but I want to make sure I'm not wasting performance. 回答1: EDIT: The spec makes some guarantees for boxing conversions. From section 5.1.7: If the value p being

Is int (Int32) considered an object in .NET or a primitive (not int?)?

别说谁变了你拦得住时间么 提交于 2019-12-12 07:14:10
问题 Is int (aka Int32 ) an object , or a primitive in .NET (I'm not asking regarding int? )? I hit F12 on the saved word int and got : public struct Int32 : IComparable, IFormattable, IConvertible, IComparable<int>, IEquatable<int> { ... } It doesn't inherit from Object , does it mean that int is a primitive ? 回答1: Everything in C# inherits from object , including int . From msdn: Int32 is an immutable value type that represents signed integers and Both reference and value types are derived from

Is there a way to write generic Java methods that work with primitive array types? [duplicate]

Deadly 提交于 2019-12-11 23:02:40
问题 This question already has answers here : Is it possible to use a primitive type (int) in as a generic type in Java? (2 answers) Closed 6 years ago . EDIT: This question specifically regards Java primitive arrays. There are other questions that address writing generic methods for primitive scalar types, but arrays are sufficiently different to warrant keeping this question around for future reference (IMHO). Consider the following Java method: private int maxIndex(double[] values, double[]

How to draw a Point Primitive with a world space width?

蓝咒 提交于 2019-12-11 18:21:36
问题 I want to draw a point, to simulate the position of which the light originates, however the issue I am facing now is that it is always the same size, regardless of the distance: I push literally one vertex to the GPU, my code: point.vs.glsl #version 440 core layout(location = 0) in vec4 position; layout(location = 0) uniform mat4 model_matrix; layout(location = 1) uniform mat4 view_matrix; layout(location = 2) uniform mat4 proj_matrix; void main(void) { gl_PointSize = 100.0; gl_Position =

What is default values for data type in java? [duplicate]

强颜欢笑 提交于 2019-12-11 04:55:02
问题 This question already has answers here : default values for primitives (3 answers) Closed 2 years ago . i am very new to java having always issue with data types so What is the Default values for all datatypes in java.? 回答1: byte 0 short 0 int 0 long 0 float 0.0f double 0.0d char '\u0000' boolean false 回答2: http://javaignite.com/post/66/default-values-for-primitives-in-java primitives dont have null value. default have for an int is 0. if(person.getId()==0){} Default values for primitives in

Haskell: Alternative, non-circular definition of Redex?

江枫思渺然 提交于 2019-12-10 22:35:59
问题 I got quite confused about what is and is not a redex in Haskell, so I spent some time on it, but I would like feedback whether I got it right. I found this definition of a redex, and it is circular; Etymology : From "reducible expression" Definition: Redex (plural redexes): (mathematics) Something to be reduced according to the rules of a formal system. http://en.wiktionary.org/wiki/redex The above definition presumes one knows how to reduce. So to me this is like saying "Bluish is the

How to create generic primitive arrays?

怎甘沉沦 提交于 2019-12-10 19:01:28
问题 This is a following question coming from Two methods for creating generic arrays. With given two methods, @SuppressWarnings("unchecked") static <T> T[] array1(final Class<T> elementType, final int size) { return (T[]) Array.newInstance(elementType, size); } static <T> T[] array2(final Class<T[]> arrayType, final int size) { return arrayType.cast(Array.newInstance(arrayType.getComponentType(), size)); } Both methods work fine for Object type. final Integer[] objectArray1 = array1(Integer.class

Primitive stream vs object stream and actual boxing that occurs

故事扮演 提交于 2019-12-10 17:23:23
问题 So I understand you can have object streams, i.e. Stream<T> and specialist primitive streams, e.g. IntStream , DoubleStream , etc. One of the benefits of the latter is to avoid autoboxing. Also if we take IntStream as an example, it has specialised operations such as filter that accepts an IntPredicate . I wondered if I had an IntStream vs a Stream<Integer> at which point you're saving on boxing, e.g. intstream.filter(x -> x >= 50).forEach(x -> System.out.println(x)); vs stream.filter(x -> x

Profiling floating point usage in C

我们两清 提交于 2019-12-10 17:16:42
问题 Is there an easy way to count the number of multiplications actually executed by a piece of standard C code? The code I have in mind basically just does additions and multiplications, and it's the multiplications that are of primary interest, but it wouldn't hurt to get counts of the other operations as well. If it were an option, I suppose I could go around replacing 'a * b' with 'multiply(a, b)' and write a cover function for the native * operator, b/c I really don't care about time

How to overcome the fact that primitives are passed by value

前提是你 提交于 2019-12-10 17:16:07
问题 I have a long piece of code that calculates two values ( doubles ) for me, I use this piece of code in a few places - to stick with DRY principles I should refactor this bit of code to a nice unit testable method. However I cant make it return two doubles, and doubles are primitive so cannot be passed by value and manipulated. The cleanest way I can think of doing this is by making this method return an double[] . Can anyone think of a better way? Thanks 回答1: Firstly, all variables are passed