primitive

Increment variable names? [duplicate]

。_饼干妹妹 提交于 2019-11-26 17:29:13
问题 This question already has answers here : Assigning variables with dynamic names in Java (7 answers) Closed 2 years ago . Okay so for what I am doing i need to increment my variables name, so for example int Taco1 = 23432..... int Taco2 = 234235656..... int Taco3 = 11111....... But instead i need it to be a variable like int X = 0; some method with loop or recursion() int Taco(X) = bla bla bla x++ Trying to get my variable names to auto name themselves incremented by 1 every time, so they don

Which one to use, int or Integer

主宰稳场 提交于 2019-11-26 15:16:51
问题 I need to create a data transfer object, which I will use for storing the records retrieved from database. In this data transfer object, I need to declare a numeric field. For that which one is better - int or Integer If I am defining the field as Integer, will there be any performance impact because of 'Integer' type if I am going to retrieve more than 2000 records from DB!? Thanks in advance. 回答1: Integer is a better option, as it can handle null ; for int , null would become 0 , silently,

How many primitives does it take to build a LISP machine? Ten, seven or five?

大城市里の小女人 提交于 2019-11-26 15:03:24
问题 On this site they say there are 10 LISP primitives. The primitives are: atom, quote, eq, car, cdr, cons, cond, lambda, label, apply . http://hyperpolyglot.wikidot.com/lisp#ten-primitives Stevey reckons there are seven (or five): Its part of the purity of the idea of LISP: you only need the seven (or is it five?) primitives to build the full machine. http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html What is the minimum number of primitives to build a LISP machine (ie

Inconsistent behavior on java's ==

你。 提交于 2019-11-26 14:45:05
问题 Consider this code: class test { public static void main(String[] args) { test inst_test = new test(); int i1 = 2000; int i2 = 2000; int i3 = 2; int i4 = 2; Integer Ithree = new Integer(2); // 1 Integer Ifour = new Integer(2); // 2 System.out.println( Ithree == Ifour ); inst_test.method( i3 , i4 ); inst_test.method( i1 , i2 ); } public void method( Integer i , Integer eye ) { System.out.println(i == eye ); } } It prints: false true false I understand the first false , the == operator only

Is it possible to use a primitive type (int) in as a generic type in Java?

爱⌒轻易说出口 提交于 2019-11-26 14:41:07
问题 Specifically, with a SortedMap<Vector<String>, int> I get "dimensions expected after this ( int ) token." Help! 回答1: No, this is not possible. Use Integer instead. Autoboxing takes care of the rest (i.e. for most purposes you can program as if you had actually used int because Java converts to and from Integer automatically for you). 回答2: Konrad is correct. Alternately, you can use the trove class TObjectIntHashMap to map Objects to primitive ints. 来源: https://stackoverflow.com/questions

Are primitive datatypes thread-safe in Java

梦想与她 提交于 2019-11-26 12:45:50
问题 Are the primitive data types like int & short thread-safe in Java? I have executed the following code and couldn\'t see expected result 500 some times. public class SampleThree extends Thread { static long wakeUpTime = System.currentTimeMillis() + (1000*20); static int inT; public static void main(String args[]) { System.out.println(\"initial:\" + inT); for(int i=0; i<500; i++) new SampleThree().start(); try { Thread.sleep(wakeUpTime - System.currentTimeMillis() + (1000*30)); System.out

Why doesn&#39;t Kotlin allow to use lateinit with primitive types?

旧巷老猫 提交于 2019-11-26 12:28:48
问题 In the Kotlin language we, by default, have to initialize each variable when it is introduced. To avoid this, the lateinit keyword can be used. Referring to a lateinit variable before it has been initialized results in a runtime exception. lateinit can not, however, be used with the primitive types. Why is it so? 回答1: For object types, Kotlin uses the null value to mark that a lateinit property has not been initialized and to throw the appropriate exception when the property is accessed. For

Primitive type &#39;short&#39; - casting in Java

て烟熏妆下的殇ゞ 提交于 2019-11-26 12:11:13
I have a question about the primitive type short in Java. I am using JDK 1.6. If I have the following: short a = 2; short b = 3; short c = a + b; the compiler does not want to compile - it says that it "cannot convert from int to short" and suggests that I make a cast to short , so this: short c = (short) (a + b); really works. But my question is why do I need to cast? The values of a and b are in the range of short - the range of short values is {-32,768, 32767}. I also need to cast when I want to perform the operations -, *, / (I haven't checked for others). If I do the same for primitive

Using int vs Integer

痞子三分冷 提交于 2019-11-26 12:08:44
问题 I came across a class using Integer variables to capture size to be used in a for loop. Is this good practice or should we use the int primitive data type? Integer size = something.getFields().size(); for (Integer j = 0; j < size - 1; ++j) 回答1: the Integer class is provided so that values can be boxed/unboxed in a pure OO manner. use int where appropriate unless you specifically need to use it in an OO way; in which case Integer is appropriate. Java Int vs Integer However, very different

How to serialize Java primitives using Jersey REST

一曲冷凌霜 提交于 2019-11-26 09:57:14
问题 In my application I use Jersey REST to serialize complex objects. This works quite fine. But there are a few method which simply return an int or boolean. Jersey can\'t handle primitive types (to my knowledge), probably because they\'re no annotated and Jersey has no default annotation for them. I worked around that by creating complex types like a RestBoolean or RestInteger, which simply hold an int or boolean value and have the appropriate annotations. Isn\'t there an easier way than