问题描述
我有一个使用以下代码的课程:
I have a class with this code:
package shop.orders.services.email
private[services] class EmailService {...}
然后在另一个包中,我使用该类:
Then in a different package, I use that class:
package shop.ui
import shop.orders.services.email.EmailService
class PaymentConfirmation extends WithFacesContext {
var emailService: EmailService = null
查看生成的字节码,没有任何访问修饰符的迹象,这很有意义,因为Java不支持这种访问限制.因此,如果我创建一个包含类似块一的代码的库,然后尝试针对该库编译块二,会发生什么情况-由于信息丢失,编译器不会失败.还是包含在清单中?
Looking at the generated bytecode, there is no sign of any access modifier, which makes sense, as Java does not support such access restrictions. So what happens if I create a library containing code like block one, and attempt to compile block two against the library - there is no chance that the compiler will fail, since the information is lost. Or is it contained in something like a manifest?
我正在使用Scala 2.9.2.
I'm using Scala 2.9.2.
推荐答案
您可以从Java引用EmailService
,但不能从Scala引用EmailService
,因为Scala将类的签名存储为scala.reflect.ScalaSignature
注释. Scala编译器将失败,并显示以下错误:
You could reference EmailService
from Java, but not from Scala, because Scala stores the signature of the class as a scala.reflect.ScalaSignature
annotation. The Scala compiler will fail with the following error:
这篇关于Scala访问限定符有哪些保证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!