To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Added in 24 Hours
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

From Wikipedia, the free encyclopedia

Static import is a feature introduced in the Java programming language that allows members (fields and methods) which have been scoped within their container class as public static, to be used in Java code without specifying the class in which the field has been defined. This feature was introduced into the language in version 5.0.

The feature provides a typesafe mechanism to include constants into code without having to reference the class that originally defined the field. It also helps to deprecate the practice of creating a constant interface (an interface that only defines constants then writing a class implementing that interface, which is considered an inappropriate use of interfaces.[1])

The mechanism can be used to reference individual members of a class:

import static java.lang.Math.PI;
import static java.lang.Math.pow;

or all the static members of a class:

import static java.lang.Math.*;

For example, this class:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        System.out.println("Considering a circle with a diameter of 5 cm, it has");
        System.out.println("a circumference of " + (Math.PI * 5) + " cm");
        System.out.println("and an area of " + (Math.PI * Math.pow(2.5, 2)) + " sq. cm");
    }
}

Can instead be written as:

import static java.lang.Math.*;
import static java.lang.System.out;

public class HelloWorld {
    public static void main(String[] args) {
        out.println("Hello World!");
        out.println("Considering a circle with a diameter of 5 cm, it has");
        out.println("a circumference of " + (PI * 5) + " cm");
        out.println("and an area of " + (PI * pow(2.5, 2)) + " sq. cm");
    }
}

YouTube Encyclopedic

  • 1/3
    Views:
    73 072
    710
    6 864
  • 7.17 Static Import in Java
  • Java Interview 07 - Static Import
  • JAVA 5 New Features | Static Import | Core Java Tutorials | by Mr.Hari Krishna

Transcription

Ambiguity

If two static members of the same name are imported from multiple different classes, the compiler will throw an error, as it will not be able to determine which member to use in the absence of class name qualification. For example, the following code will fail to compile:

import static java.lang.Integer.*;
import static java.lang.Long.*;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println(MAX_VALUE);
    }
}

In this case, MAX_VALUE is ambiguous, as the MAX_VALUE field is an attribute of both java.lang.Integer and java.lang.Long. Prefixing the field with its class name will disambiguate the class from which MAX_VALUE is derived, but doing so makes the use of a static import redundant.[2]

Notes

References

This page was last edited on 5 October 2023, at 15:52
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.