What are the guarantees for scala access qualifiers?

邮差的信 提交于 2020-01-03 08:18:11

问题


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

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?

I'm using Scala 2.9.2.


回答1:


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:

class EmailService in package email cannot be accessed in package shop.orders.services.email



来源:https://stackoverflow.com/questions/13712506/what-are-the-guarantees-for-scala-access-qualifiers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!