簡體   English   中英

之間的區別是需要公共VS需要Java 9中的可傳遞

[英]What is difference between requires public VS requires transitive in Java 9

我了解到,為了使用任何其他出口模塊,我們需要指定模塊的requires

module mymodule{
       requires othermodule.xyz;
}

othermodule使用上thirdmodulemymodule需要,作為好, othermodule應該這樣定義傳遞依賴:

module othermodule {
       requires transitive thirdmodule  
}

但是,我已經看到許多網站在這種情況下使用public關鍵字:

module othermodule {
       requires public  thirdmodule  
}

兩種形式之間有什么區別? requires publicrequires transitive

requires public是Java 9發行之前修訂的modules子語言的早期版本的一部分。根據Java 9 JLS,在ModuleDirective中不允許使用public關鍵字:請參見JLS 7.7

使用requires public語法的網站已過期/不正確。 例如,以下內容對此進行了確認:

基本上requires public語法已經過時(現在無效),並且requires transitive是其替代。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM