zoukankan      html  css  js  c++  java
  • package-info.java https://www.intertech.com/Blog/whats-package-info-java-for/

     

    mybatis-3/src/main/java/org/apache/ibatis/cache/package-info.java

    What’s package-info.java for?

    https://www.intertech.com/Blog/whats-package-info-java-for/

     mybatis-3/src/main/java/org/apache/ibatis/cache/package-info.java

    by  | Jul 3, 2013

    In some recent classes, my students have encountered a package-info.java file tucked inside of some of the sample code we get from courseware providers.  “What’s that thing?”, they usually ask.

    package-info.java’s purpose

    The package-info.java is a Java file that can be added to any Java source package.  Its purpose is to provide a home for package level documentation and package level annotations. Simply create the package-info.java file and add the package declaration that it relates to in the file.  In fact, the only thing the package-info.java file must contain is the package declaration.

    The package-info.java file above must sit in the com.intertech.services package.

    Package Documentation

    Prior to Java 5, package level documentation (the documentation shown in Javadocs for a package) was placed in package.html.  Today, the description and other related documentation for a package can be written up in the package-info.java file and it gets used in the production of the Javadocs.  As a demonstration, the example package-info.java…

    … results in the following Javadocs.

    Package Annotations

    Perhaps more importantly to today’s annotation driven programmer, the package-info.java file contains package level annotations. An annotation with ElementType.PACKAGE as one of its targets is a package-level annotation and there are many of them.  Using your favorite IDE’s code assistant (shown in Eclipse below) in a package-info.java file and you will find a number package annotation options.

    For example, perhaps you want to deprecate all the types in a package. You could annotate each individual type (the classes, interfaces, enums, etc. defined in their .java files) with @Deprecated (as shown below).

    Or, you could use the @Deprecated on the package declaration in package-info.java.  This has the effect of deprecating everything in the package in one fell swoop.

    Help adding package-info.java to your packages

    While you can add the package-info.java file to your packages by hand (just as you can create Java classes by hand), IDE’s often offer you the option to include a package-info.java file each time you create a new package.  Eclipse, shown below, offers a simple (and often overlooked) checkbox in the New Java Package creation wizard.


    Wrap Up
    So now you know what that package-info.java file is all about and you know how to use it.

    Like to learn more about Java or other Java related topics? Take a look at the Java Training courses that we provide.

    Intertech also provides Java Consulting for those looking for some help with development projects. See what we can do for you!

  • 相关阅读:
    封装组件集合
    Vue组件封装(以封装一个button组件为例)
    Spark权威指南读书笔记(四) 聚合与连接
    leetcode刷题笔记一百三十五题 分发糖果
    leetcode刷题笔记一百三十四题 加油站
    leetcode刷题笔记一百三十三题 克隆图
    leetcode刷题笔记一百三十一与一百三十二题 分割回文串与分割回文串II
    leetcode刷题笔记一百三十题 被围绕的区域
    leetcode刷题笔记一百二十九题 求根到叶子节点数字之和
    leetcode刷题笔记一百二十八题 最长连续序列
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10186382.html
Copyright © 2011-2022 走看看