Home > 类库下载 > java类库 > Java final argument

Java final argument

高洛峰
Release: 2016-11-02 15:06:04
Original
1853 people have browsed it

Java 1.1 allows us to make arguments final by declaring them appropriately in the argument list. This means that inside a method, we cannot change what the argument handle points to. As shown below:

/**
 * Created by xfyou on 2016/11/2.
 * final自变量演示
 */
public class FinalArguments {
    void with(final Gizmo g) {
        //! g = new Gizmo();    // Illegal -- g is final
        g.spin();
    }

    void without(Gizmo g) {
        g = new Gizmo();    // OK -- g not final
        g.spin();
    }

    // void f(final int i) { i++; } // Can't change
    // You can only read from a final primitive:
    int g(final int i) {
        return i + 1;
    }

    public static void main(String[] args) {
        FinalArguments bf = new FinalArguments();
        bf.without(null);
        bf.with(null);
    }
}

class Gizmo {
    public void spin() {
    }
}
Copy after login


Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template