5

さて、次を使用するプロジェクトがあったとします。

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Color;
import java.awt.Polygon;

クラスファイルを小さくして使用できますか:

import java.awt.*

いらないものをたくさん輸入しているので、反対を考えています。ファイルの文字数が大幅に少なくなるためだと考えています。

4

10 に答える 10

17

No difference. These are a compile-time construct only.

于 2009-02-25T09:17:58.223 に答える
3

The Java import statement does not add any size to the class file. It allows the compiler to deduce what names refer to at compile time.

The only difference the line

import java.util.*;

makes is that you can write:

Set<String> set;

rather than:

java.util.Set<String> set;
于 2009-02-25T09:20:52.163 に答える
1

クラスのサイズを小さくすることに興味がある場合は、ゲーム作成コンテストの java4kにいくつかのヒントがあります。たとえば、このページhttp://www.ahristov.com/tutorial/java4k-tips/java4k-tips.html

于 2009-02-25T10:18:35.753 に答える
1

I think that Java only includes that stuff you really need... So there won't be any difference in the final compiled version using one or the other way.

于 2009-02-25T09:16:27.667 に答える
1

Honestly, why do you care about the size of your class file ?

It is a better practice to explicitly include all classes needed instead of doing a "import foo.bar.*".

That makes your code more readable, and more maintainable.

于 2009-02-25T09:16:59.083 に答える
1

No change at all in the generated class file.

Imports only have influence on the compiler (which might take a little bit longer if it has to index a lot of directories) and, of course, on the source code (which is IMO more maintainable when you can see exactly which classes are used).

于 2009-02-25T09:18:40.860 に答える
0

以前の投稿で述べたように違いはありませんが、私の意見ではコードが読みやすくなるので、好みとして厳密なインポートを使用します

于 2009-02-25T09:34:06.063 に答える
0

以前の回答を補完するために、表示される唯一の違いは、ワイルドカードを指定するのではなく、何千もの不要なパッケージやクラスを含めることができる、何を編集したいかを明示的に指定すると、コンパイルが少しimport速くなることです。 。

于 2009-02-25T09:49:22.923 に答える