2

I was looking at the source of List.map in Functional Java and saw it was using some class called Buffer, but couldn't find the class anywhere, then I looked at the imports and realized it was an inner class. But the import line looked funny:

import static fj.data.List.Buffer.*;

What does it do? Why is it importing from itself?

4

3 回答 3

3

import static fj.data.List.Buffer.*将 的所有静态成员Buffer导入范围。否则,对文件中静态成员的所有引用Buffer(除了从内部进行的引用Buffer)都需要以 . 为前缀Buffer.

而不是这个:

final Buffer<B> bs = Buffer.empty();

可以在文件的任何地方写这个:

final Buffer<B> bs = empty();

可以避免使用通配符。他们本可以import static fj.data.List.Buffer.empty为他们使用的每个其他静态成员编写另一个导入 from Buffer,但可以说通配符在这里很好,因为它是从同一个文件中导入的。

于 2013-04-21T17:32:50.663 回答
1

它正在导入static里面的所有元素fj.data.List.Buffer。通过这样做,您只需要调用Something而不是fj.data.list.Buffer.Something.

更多信息:

于 2013-04-21T15:57:24.650 回答
0

这意味着将导入所有静态字段和方法。并且在导入类时无需类名前缀即可访问它们。

于 2013-04-21T15:56:57.987 回答