问题描述
我看到scala.reflect.io.File类,这是否应该帮助文件操作?我应该更喜欢使用这个而不是java.io.File?这个类的目的是什么?
你也不应该使用 java.nio .file
,当然。
如果您想用特殊的运算符增强该API,请使用扩展方法。该代码的作者在邮件列表上表示了很多。被困在Java 6被认为是不幸的。
你指向的包被拉到 scala-reflect.jar
来支持反射,但是对于它的不支持状态,无处不在的警告。
$ b
AbstractFile
抽象被使用位置
,它有一个源文件。你从中得到的文件是一个 java.io.File
,但是 AbstractFile
reflect.io.Path
抽象(带有文件
和目录
亚型)。所以所有的代码都保留在一起打包。
我必须停下来思考每一次 在背面说: AbstractFile
和 File $ c $穿过我的路(双语警报)。我曾经有一个紫色的
。 AbstractFile
就像完全不同于 File
的T恤,但它穿着
Position
与<$ c $无关c> io.Position
以下是触及 api.Position
,当然它在scaladoc中是面向用户的;注意它是一个Java文件:
/ **这个位置的源文件对应的Java文件。
*
*返回类型是scala.reflect.io.AbstractFile,属于Scala反射的一个实验部分。
*除非您知道自己在做什么,否则不应使用它。在后来的版本中,这个API将被改进
*并作为scala.reflect.api的一部分公开。
*
* @group Common
* /
def source:scala.reflect.internal.util.SourceFile
为了回答你的第一个问题,我认为可以肯定地说,是的,它应该是有帮助的。
I see the scala.reflect.io.File class, is this supposed to help with file operations? Am I supposed to prefer to use this rather than java.io.File? What is the purpose of this class?
Neither, you're supposed to use java.nio.file
, of course.
If you want to "enhance" that API with fancy operators, use extension methods. The author of that code has said as much on the mailing list. Being stuck on Java 6 is considered unfortunate.
The package you're pointing to was pulled into the scala-reflect.jar
to support reflection, but warnings are everywhere about its unsupported status.
The AbstractFile
abstraction is used by Position
, which has a source file. The "file" you get from that is a java.io.File
, but AbstractFile
has factory methods that take the reflect.io.Path
abstraction (with File
and Directory
subtypes). So all that code remains packaged together.
I have to stop and think every time AbstractFile
and File
cross my path (pun alert). I used to have a purple "AbstractFile
is, like, totally different from File
" t-shirt, but it wore out with multiple washings.
On the back it said, "Position
has nothing to do with io.Position
."
Here is the warning as it touches api.Position
, where of course it is user-facing in the scaladoc; notice it says it is a "Java file":
/** Java file corresponding to the source file of this position.
*
* The return type is `scala.reflect.io.AbstractFile`, which belongs to an experimental part of Scala reflection.
* It should not be used unless you know what you are doing. In subsequent releases, this API will be refined
* and exposed as a part of scala.reflect.api.
*
* @group Common
*/
def source: scala.reflect.internal.util.SourceFile
To answer your first question, I think it's safe to say, Yes, it was supposed to help.
这篇关于在Scala中使用import scala.reflect.io.File或java.io.File会更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!