• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

import static package

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.*;
import static java.util.Collections.sort;//#1

public class Sortee {
public static void main(String[] args){
List x = new ArrayList();
x.add(5);
x.add(new Integer(42));
x.add(new Integer(17));
x.add(Integer.parseInt("812"));
sort(x);
System.out.println(x);
}
}

In this java source.#1 use the static import to invoke sort() method.
what's the reason.
It's the first time saw static import.How to use static to modify package.
If we change the #1 to:
import java.util.Collections;
What else should we do to make this java source run well?
Thanks!
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


In this java source.#1 use the static import to invoke sort() method.
what's the reason.
It's the first time saw static import.How to use static to modify package.



Basically, "static import" was a feature that was added with Java 5. With static import, you can import a static variable or static method of another class into your class. This way, you can use the static variable or static method, as if it was declared in your class.

IMHO, I think this confuses more than it helps... but I don't get a vote.

Henry
 
Cao Bin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry to give so much trouble.
I hope this change will confirm with regulation.
It's my real name.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If we change the #1 to:
import java.util.Collections;
What else should we do to make this java source run well?



How do we call any static method?
 
Why is the word "abbreviation" so long? And this ad is so short?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic