String is immutable. What exactly is the meaning?

This question already has an answer here: Immutability of Strings in Java 23 answers Before proceeding further with the fuss of immutability, let's just take a look into the String class and its functionality a little before coming to any conclusion. This is how String works: String str = "knowledge"; This, as usual, creates a string containing "knowledge" and assigns it a r

字符串是不可变的。 究竟是什么意思?

这个问题在这里已经有了答案: Java中字符串的不变性23回答 在继续讨论不可变性的问题之前,我们先来看看String类及其功能,然后再做出结论。 这是String工作原理: String str = "knowledge"; 像往常一样,这将创建一个包含"knowledge"的字符串,并为其分配一个引用str 。 够简单? 让我们执行一些更多的功能: String s = str; // assigns a new reference to the same string "knowledge" 让我们

Why can't I define a static method in a Java interface?

Here's the example: public interface IXMLizable<T> { static T newInstanceFromXML(Element e); Element toXMLElement(); } Of course this won't work. But why not? One of the possible issues would be, what happens when you call: IXMLizable.newInstanceFromXML(e); In this case, I think it should just call an empty method (ie {}). All subclasses would be forced to implement the

为什么我无法在Java界面中定义静态方法?

这是一个例子: public interface IXMLizable<T> { static T newInstanceFromXML(Element e); Element toXMLElement(); } 当然这是行不通的。 但为什么不呢? 其中一个可能的问题是,当你打电话时会发生什么: IXMLizable.newInstanceFromXML(e); 在这种情况下,我认为它应该只调用一个空方法(即{})。 所有的子类都将被迫实现静态方法,所以在调用静态方法时它们都会很好。 那为什么不可能呢? 编辑:我

In Java, what is a shallow copy?

java.util.Calendar.clone() returns "...a new Calendar with the same properties" and returns "a shallow copy of this Calendar". This does not appear to be a shallow copy as answered here on SO. That question is tagged language-agnostic, Java does not seem to follow the language agnostic definition. As I step through the code I notice that the structure and the elements are

在Java中,什么是浅拷贝?

java.util.Calendar.clone()返回“...具有相同属性的新日历”并返回“此日历的浅表副本”。 这看起来并不像在SO上回答的浅拷贝。 这个问题被标记为与语言无关, Java似乎没有遵循语言不可知的定义。 当我遍历代码时,我注意到结构和元素被复制到这个新对象,而不仅仅是语言不可知的结构。 在Java中,什么是浅拷贝? 它与Java深层副本(如果存在的话)有什么区别? 浅拷贝只复制类中引用的值。 深拷贝复制这些值。 给定

Arrays in Java and how they are stored in memory

I'm trying to understand the array setup in java. Why must you initialize space for each each object in the array, after you have created the array. How is it stored in memory like this: [object][object] or like this: [*class]->[object] [*class]->[object] In other words, what is actually being done in memory. Does array[0] = new class() just return a reference to a reserved loc

Java中的数组以及它们如何存储在内存中

我想了解java中的数组设置。 为什么必须在创建数组后为数组中的每个对象初始化空间。 它如何像这样存储在内存中: [object][object] 或者像这样: [*class]->[object] [*class]->[object] 换句话说,实际上在记忆中做了什么。 array[0] = new class()返回对内存中保留位置的引用,并且class[] array = new class[10]语句会沿着10个指针的行创建一些内容,稍后将分配给新的陈述? Java中的数组存储以下两件事之

changing address of object in Java (pass

Before I post my question, I have read the following excellent articles on java-pass-by-value. I am convinced I have understood it well. Is Java "pass-by-reference" or "pass-by-value"? http://www.javaworld.com/article/2077424/learn-java/does-java-pass-by-reference-or-pass-by-value.html My question has to do with a side-by comparison of Java with other language that supp

改变Java中对象的地址(pass

在发布我的问题之前,我已阅读了关于java-pass-by-value的以下优秀文章。 我确信我已经很好地理解了。 Java是“通过引用传递”还是“按值传递”? http://www.javaworld.com/article/2077424/learn-java/does-java-pass-by-reference-or-pass-by-value.html 我的问题与Java与其他支持pass-by-reference语言( C++可能)之间的边界比较有关。 在Java情况下,你有一个句柄(引用)指向位置A中的对象,所以对象本身可以被修改

Why does the specified object be eligible for garbage collection?

For the record, I'm NOT a Java Beginner, but -- rather - an intermediate-level guy who kinda forgot a bit about fundamentals about Java. class C{ public static void main(String a[]){ C c1=new C(); C c2=m1(c1); //line 4 C c3=new C(); c2=c3; // line 6 anothermethod(); } static C m1(C ob1){ ob1 =new C(); // lin

为什么指定的对象有资格进行垃圾回收?

为了记录,我不是 Java初学者,而是 - 一个中级别的人,他有点忘了Java的基础知识。 class C{ public static void main(String a[]){ C c1=new C(); C c2=m1(c1); //line 4 C c3=new C(); c2=c3; // line 6 anothermethod(); } static C m1(C ob1){ ob1 =new C(); // line 10 return ob1; } void anothermethod(){} }

Passing object to method in java appears to be by reference (and Java is by val)

I thought when you passed objects to methods in Java, they were supposed to be by value. Here is my code: public class MyClass{ int mRows; int mCols; Tile mTiles[][]; //Custom class //Constructor public MyClass(Tile[][] tiles, int rows, int cols) { mRows = rows; mCols = cols; mTiles = new Tile[mRows][mCols]; for (int i=0; i < mRows;

在java中将对象传递给方法似乎是通过引用(而Java是通过val)

我认为当你将对象传递给Java中的方法时,它们应该是有价值的。 这是我的代码: public class MyClass{ int mRows; int mCols; Tile mTiles[][]; //Custom class //Constructor public MyClass(Tile[][] tiles, int rows, int cols) { mRows = rows; mCols = cols; mTiles = new Tile[mRows][mCols]; for (int i=0; i < mRows; i++) { for (int j=0;

what is the difference between pass by reference and call by reference?

在java中通过引用和引用引用有什么区别? Java does not pass any variables by reference. It is tempting to think of objects being passed by reference in Java -- but harmful. Variables of object type are references. When passed, they are passed by value. In other languages, pass-by-reference and call-by-reference are the same thing. Edit: More detail is provided in the existing stackoverflow

引用传递与引用引用有什么区别?

在java中通过引用和引用引用有什么区别? Java不会通过引用传递任何变量。 很容易想到在Java中通过引用传递对象 - 但是有害的。 对象类型的变量是引用。 一旦通过,它们就会通过价值传递。 在其他语言中,传引用和引用引用是一回事。 编辑:在现有的stackoverflow问题中提供了更多细节“Java是否通过引用传递?” (剧透:没有) 重要的概念 - Java没有“通过引用传递”的概念。 Java中的所有东西都是按值传递的。 当

What exactly does "pass by reference" mean?

And who has the authority to decide? Edit: Apparently I haven't succeeded in formulating my question well. I am not asking how Java's argument passing works. I know that what looks like a variable holding an object is actually a variable holding a reference to the object, and that reference is passed by value. There are lots of fine explanations of that mechanism here (in the linked

“通过引用传递”究竟意味着什么?

谁有权决定? 编辑:显然我没有成功地制定我的问题。 我不是在问Java如何传递参数。 我知道看起来像一个持有对象的变量实际上是一个持有对该对象的引用的变量,并且该引用是通过值传递的。 这里有很多关于该机制的细节解释(在链接的线程和其他地方)以及其他地方。 问题是关于术语传递参考的技术含义。 (结束编辑) 我不确定这是否是SO的正确问题,如果不是,我表示歉意,但我不知道更好的地方。 在这里的其他问题

java: pass

I'd two code snippets: First class PassByTest{ public static void main(String... args){ PassByTest pbt=new PassByTest(); int x=10; System.out.println("x= "+x); pbt.incr(x);//x is passed for increment System.out.println("x= "+x);//x is unaffected } public void incr(int x){ x+=1; } } In this code the value of x is unaffected.

java:pass

我有两个代码片段: 第一 class PassByTest{ public static void main(String... args){ PassByTest pbt=new PassByTest(); int x=10; System.out.println("x= "+x); pbt.incr(x);//x is passed for increment System.out.println("x= "+x);//x is unaffected } public void incr(int x){ x+=1; } } 在这个代码中, x的值不受影响。 第二 import java.io