Why does the JVM allow to set the "high" value for the IntegerCache, but not the "low"?

We all know that Java has a cache for Integer (and some other types) for number in the range [-128, 127] which are considered to be "commonly used". The cache is designed as follow : private static class IntegerCache { static final int low = -128; static final int high; static final Integer cache[]; static { // high value may be configured by property

为什么JVM允许为IntegerCache设置“高”值,而不是“低”?

我们都知道Java有一个Integer (和一些其他类型)的缓存,用于范围[-128, 127]中被认为是“常用”的数字。 缓存设计如下: private static class IntegerCache { static final int low = -128; static final int high; static final Integer cache[]; static { // high value may be configured by property int h = 127; String integerCacheHighPropValue = sun.misc.VM

Using arrays of arrays as pointers to expandable lists of classes in Java

Reading the first answer in the Passing a String by Reference in Java? I (as on old pointer freaked C nerd) have a question regarding using arrays as pointers in java. I have a variably number of EditText boxes in a setup routine for an number of strings to be stored. This includes a add one EditText box button. So on screen the button is followed by an number of EditText boxes. I have a si

使用数组数组作为指向Java中可扩展的类列表的指针

阅读在Java中通过引用传递字符串中的第一个答案? 我(如在旧的指针吓坏了C书呆子)有一个关于在java中使用数组作为指针的问题。 在一个设置例程中,有多个可编辑的EditText框用于存储多个字符串。 这包括添加一个EditText框按钮。 所以在屏幕上,按钮之后是一些EditText框。 我有一个类似的URL来存储。 而不是像20行代码一样重复一遍又一遍地处理不同的这样的设置数据项,对于方法(C中的函数)来说显然是一种情况,问

Java class file from PL/SQL procedure

I have a following PL/SQL procedure: CREATE OR REPLACE PROCEDURE getDogInfo (Dog_ID IN NUMBER, Dog_name OUT VARCHAR) AS BEGIN SELECT Dog_name INTO Name FROM Dog_family WHERE ID = Dog_ID; END; I need to make a java class file that does the same. I've been trying like this: import java.sql.*; import java.io.*; public class Procedure { public static void getDogInfo (int Dog_ID, Str

来自PL / SQL过程的Java类文件

我有一个下面的PL / SQL过程: CREATE OR REPLACE PROCEDURE getDogInfo (Dog_ID IN NUMBER, Dog_name OUT VARCHAR) AS BEGIN SELECT Dog_name INTO Name FROM Dog_family WHERE ID = Dog_ID; END; 我需要创建一个java类文件,它也是这样做的。 我一直在尝试像这样: import java.sql.*; import java.io.*; public class Procedure { public static void getDogInfo (int Dog_ID, String Dog_name) throws SQLE

SWIG, can I assign a value to a char** passed from Java to C

I have a C API that looks like this: int my_function(char** assign_me_a_string); I basically need the native code to tell me a value. If I do: char* my_function(); It works fine. I get a String in return that I can use in Java. However I would prefer to use the first approach since all my functions returns an int by default (status value). I have tried to use various.i and this typemap:

SWIG,我可以为从Java传递到C的char **分配一个值

我有一个C API,看起来像这样: int my_function(char** assign_me_a_string); 我基本上需要本地代码来告诉我一个价值。 如果我做: char* my_function(); 它工作正常。 我得到一个可以在Java中使用的字符串。 不过,我宁愿使用第一种方法,因为我所有的函数默认返回一个int(状态值)。 我试图使用various.i和这个typemap: %apply char **STRING_ARRAY { char **assign_me_a_string } 这样做我得到一个为Java API生

How does String works as Object in Java

I am quite confused with how Object works in Java since I run into this problem. Let's say I have a function called checkDateValue (code looks like this) private boolean checkDateValue(Date d1, String msg) { if (d1 == null) { msg = "d1 is null!"; return false; } return true; } Here is the place I call this function: String msg = null; Date d1 = null; if (!chec

String如何在Java中作为Object使用

由于遇到这个问题,我对Object在Java中的工作方式感到困惑。 比方说,我有一个名为checkDateValue的函数(代码如下所示) private boolean checkDateValue(Date d1, String msg) { if (d1 == null) { msg = "d1 is null!"; return false; } return true; } 这里是我称之为这个功能的地方: String msg = null; Date d1 = null; if (!checkDateValue(d1, msg)) { system.println(msg); //msg

String in Java is object, so it should be reference?

This question already has an answer here: Is Java “pass-by-reference” or “pass-by-value”? 79 answers The object's reference is passed to the method and assigned to the parameter, which is a kind of local variable. Assigning a different object reference to the parameter does nothing to the variable outside the method that held a reference to the original object. Also String is immutab

Java中的字符串是对象,所以它应该是引用?

这个问题在这里已经有了答案: Java是“通过引用传递”还是“按值传递”? 79个答案 该对象的引用被传递给该方法并被分配给该参数,该参数是一种局部变量。 为参数指定一个不同的对象引用对持有对原始对象的引用的方法以外的变量没有任何作用。 此外,String是不可变的,因此无法更改其值(例如setValue()方法)。 行str = "welcome"; 不会更改任何字符串的值 - 字符串永远不会更改它们的值。 它所做的是使一

Method to return string

So I'm doing a simple encryption program in Java. The user inputs a string (strTarget), and then that string is taken to this function. In the for-loop, it should take the character's ASCII value, reduce it by 4, and then return it to the string (doing that for all characters in the string). As you see my friends, I have already done that, however, I am not sure on how to reconstruct t

返回字符串的方法

所以我正在用Java做一个简单的加密程序。 用户输入一个字符串(strTarget),然后该字符串被带到这个函数。 在for循环中,它应该采用该字符的ASCII值,将其减少4,然后将其返回给字符串(对字符串中的所有字符执行该操作)。 正如你看到我的朋友,我已经这样做了,但是,我不确定如何重建我想要返回的字符串(例如,如果用户输入'efg',返回的字符串应该是'abc')。 所以,这是我得到这些建议的结果。 我

Object by Reference vs. Reference by Value

I read this comment here: Passing a String by Reference in Java? Yes, it's a misconception. It's a huge, widespread misconception. It leads to an interview question I hate: ("how does Java pass arguments"). I hate it because roughly half of the interviewers actually seem to want the wrong answer ("primitives by value, objects by reference"). The right answer take

按参考对象与按值参照

我在这里阅读此评论:在Java中通过引用传递字符串? 是的,这是一种误解。 这是一个巨大的,广泛的误解。 它导致我讨厌的一个采访问题:(“Java如何传递参数”)。 我讨厌这个问题,因为大约一半的采访者似乎都想要错误的答案(“基于价值的原语,参考对象”)。 正确的答案需要更长的时间才能完成,而且似乎也混淆了其中一些问题。 他们不会相信:我发誓我没有通过技术筛选,因为CSMajor-type筛选器在大学里听到了这种误解,

How to make fuction which add String into String?

This question already has an answer here: Passing a String by Reference in Java? 13 answers How do I concatenate two strings in Java? 19 answers I think you want something like this: public String addLine(String one, String two){ return one+two; } Note, this returns a string, so in main do something like: text = addLine(text, "line1"); Make sure you create it as a method: publi

如何使字符串添加到字符串功能?

这个问题在这里已经有了答案: 在Java中通过引用传递字符串? 13个答案 如何在Java中连接两个字符串? 19个答案 我想你想要这样的东西: public String addLine(String one, String two){ return one+two; } 注意,这会返回一个字符串,所以在main中做类似的事情: text = addLine(text, "line1"); 确保你创建它作为一种方法: public class Text { private String text = "Hello"; public Text(){} public Te

Pointer with java and string variable

This question already has an answer here: Passing a String by Reference in Java? 13 answers First you are assigning the value "hello" (at some place in memory) to test : test --------------> "hello" Then, you are setting myname to the same location in memory. test --------------> "hello" / myname ----------/ Then, you are assigning the value "how ar

指针与Java和字符串变量

这个问题在这里已经有了答案: 在Java中通过引用传递字符串? 13个答案 首先你要分配值“hello”(在内存中的某个地方)来test : test --------------> "hello" 然后,您将myname设置为内存中的相同位置。 test --------------> "hello" / myname ----------/ 然后,你正在分配价值“你好吗?” 在内存中的新位置进行test : -> "hello" / myname -----