3-2 案例准备工作
生活随笔
收集整理的這篇文章主要介紹了
3-2 案例准备工作
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
定義注解
java.lang.annotation.Target
?
/** Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.*********************/package java.lang.annotation;/*** Indicates the contexts in which an annotation type is applicable. The* declaration contexts and type contexts in which an annotation type may be* applicable are specified in JLS 9.6.4.1, and denoted in source code by enum* constants of {@link ElementType java.lang.annotation.ElementType}.** <p>If an {@code @Target} meta-annotation is not present on an annotation type* {@code T} , then an annotation of type {@code T} may be written as a* modifier for any declaration except a type parameter declaration.** <p>If an {@code @Target} meta-annotation is present, the compiler will enforce* the usage restrictions indicated by {@code ElementType}* enum constants, in line with JLS 9.7.4.** <p>For example, this {@code @Target} meta-annotation indicates that the* declared type is itself a meta-annotation type. It can only be used on* annotation type declarations:* <pre>* @Target(ElementType.ANNOTATION_TYPE)* public @interface MetaAnnotationType {* ...* }* </pre>** <p>This {@code @Target} meta-annotation indicates that the declared type is* intended solely for use as a member type in complex annotation type* declarations. It cannot be used to annotate anything directly:* <pre>* @Target({})* public @interface MemberType {* ...* }* </pre>** <p>It is a compile-time error for a single {@code ElementType} constant to* appear more than once in an {@code @Target} annotation. For example, the* following {@code @Target} meta-annotation is illegal:* <pre>* @Target({ElementType.FIELD, ElementType.METHOD, ElementType.FIELD})* public @interface Bogus {* ...* }* </pre>** @since 1.5* @jls 9.6.4.1 @Target* @jls 9.7.4 Where Annotations May Appear*/ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) public @interface Target {/*** Returns an array of the kinds of elements an annotation type* can be applied to.* @return an array of the kinds of elements an annotation type* can be applied to*/ElementType[] value(); }?
java.lang.annotation.RetentionPolicy
/** Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.*********************/package java.lang.annotation;/*** Annotation retention policy. The constants of this enumerated type* describe the various policies for retaining annotations. They are used* in conjunction with the {@link Retention} meta-annotation type to specify* how long annotations are to be retained.** @author Joshua Bloch* @since 1.5*/ public enum RetentionPolicy {/*** Annotations are to be discarded by the compiler.*/SOURCE,/*** Annotations are to be recorded in the class file by the compiler* but need not be retained by the VM at run time. This is the default* behavior.*/CLASS,/*** Annotations are to be recorded in the class file by the compiler and* retained by the VM at run time, so they may be read reflectively.** @see java.lang.reflect.AnnotatedElement*/RUNTIME }RUNTIME,注解會在CLASS的字節(jié)碼文件中存在,在運行時通過反射可以拿到。SOURCE在編譯的時候就會被忽略掉。
com.mmall.concurrency.annoations.ThreadSafe
?
package com.mmall.concurrency.annoations;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;/*** 課程里用來標記線程安全的類或者寫法*/ @Target(ElementType.TYPE) @Retention(RetentionPolicy.SOURCE) public @interface ThreadSafe {String value() default ""; }com.mmall.concurrency.annoations.NotThreadSafe
?
package com.mmall.concurrency.annoations;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;/*** 課程里用來標記【線程不安全】的類或者寫法*/ @Target(ElementType.TYPE) @Retention(RetentionPolicy.SOURCE) public @interface NotThreadSafe {String value() default ""; }?
com.mmall.concurrency.annoations.Recommend
package com.mmall.concurrency.annoations;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;/*** 課程里用來標記【推薦】的類或者寫法*/ @Target(ElementType.TYPE) @Retention(RetentionPolicy.SOURCE) public @interface Recommend {String value() default ""; }?
com.mmall.concurrency.annoations.NotRecommend
?
package com.mmall.concurrency.annoations;import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;/*** 課程里用來標記【不推薦】的類或者寫法*/ @Target(ElementType.TYPE) @Retention(RetentionPolicy.SOURCE) public @interface NotRecommend {String value() default ""; } Microsoft Windows [版本 10.0.17134.407] (c) 2018 Microsoft Corporation。保留所有權(quán)利。C:\Users\ZHONGZHENHUA\imooc\concurrency>git status On branch master Your branch is up-to-date with 'origin/master'.Untracked files:(use "git add <file>..." to include in what will be committed ).gitignoremvnwmvnw.cmdpom.xmlsrc/nothing added to commit but untracked files present (use "git add" to track)C:\Users\ZHONGZHENHUA\imooc\concurrency>git status On branch master Your branch is up-to-date with 'origin/master'.Untracked files:(use "git add <file>..." to include in what will be committed).gitignoremvnwmvnw.cmdpom.xmlsrc/nothing added to commit but untracked files present (use "git add" to track)C:\Users\ZHONGZHENHUA\imooc\concurrency>git add . warning: LF will be replaced by CRLF in .gitignore. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in mvnw. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in mvnw.cmd. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in pom.xml. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in src/main/java/com/mmall/concurrency/ConcurrencyApplication.java. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in src/main/java/com/mmall/concurrency/ServletInitializer.java. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in src/test/java/com/mmall/concurrency/ConcurrencyApplicationTests.java. The file will have its original line endings in your working directory.C:\Users\ZHONGZHENHUA\imooc\concurrency>git status On branch master Your branch is up-to-date with 'origin/master'.Changes to be committed:(use "git reset HEAD <file>..." to unstage)new file: .gitignorenew file: mvnwnew file: mvnw.cmdnew file: pom.xmlnew file: src/main/java/com/mmall/concurrency/ConcurrencyApplication.javanew file: src/main/java/com/mmall/concurrency/ServletInitializer.javanew file: src/main/resources/application.propertiesnew file: src/test/java/com/mmall/concurrency/ConcurrencyApplicationTests.javaC:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -am 'init' [master 42a1cd3] 'init'8 files changed, 604 insertions(+)create mode 100644 .gitignorecreate mode 100644 mvnwcreate mode 100644 mvnw.cmdcreate mode 100644 pom.xmlcreate mode 100644 src/main/java/com/mmall/concurrency/ConcurrencyApplication.javacreate mode 100644 src/main/java/com/mmall/concurrency/ServletInitializer.javacreate mode 100644 src/main/resources/application.propertiescreate mode 100644 src/test/java/com/mmall/concurrency/ConcurrencyApplicationTests.javaC:\Users\ZHONGZHENHUA\imooc\concurrency>git push Counting objects: 22, done. Delta compression using up to 4 threads. Compressing objects: 100% (14/14), done. Writing objects: 100% (22/22), 7.62 KiB | 976.00 KiB/s, done. Total 22 (delta 0), reused 0 (delta 0) remote: Powered by Gitee.com To gitee.com:lvyinhaolaiwu/concurrency.git52f2dc8..42a1cd3 master -> masterC:\Users\ZHONGZHENHUA\imooc\concurrency>git status On branch master Your branch is up-to-date with 'origin/master'.Changes to be committed:(use "git reset HEAD <file>..." to unstage)new file: src/main/java/com/mmall/concurrency/TestController.javanew file: src/main/java/com/mmall/concurrency/annoations/NotRecommend.javanew file: src/main/java/com/mmall/concurrency/annoations/NotThreadSafe.javanew file: src/main/java/com/mmall/concurrency/annoations/Recommend.javaChanges not staged for commit:(use "git add <file>..." to update what will be committed)(use "git checkout -- <file>..." to discard changes in working directory)modified: src/main/java/com/mmall/concurrency/TestController.javamodified: src/main/java/com/mmall/concurrency/annoations/NotRecommend.javamodified: src/main/java/com/mmall/concurrency/annoations/NotThreadSafe.javamodified: src/main/java/com/mmall/concurrency/annoations/Recommend.javaUntracked files:(use "git add <file>..." to include in what will be committed)src/main/java/com/mmall/concurrency/annoations/ThreadSafe.javaC:\Users\ZHONGZHENHUA\imooc\concurrency>git add ThreadSafe fatal: pathspec 'ThreadSafe' did not match any filesC:\Users\ZHONGZHENHUA\imooc\concurrency>git add src/main/java/mmall/concurrency/annoations/ThreadSafe fatal: pathspec 'src/main/java/mmall/concurrency/annoations/ThreadSafe' did not match any filesC:\Users\ZHONGZHENHUA\imooc\concurrency>git add src/main/java/mmall/concurrency/annoations/ThreadSafe.java fatal: pathspec 'src/main/java/mmall/concurrency/annoations/ThreadSafe.java' did not match any filesC:\Users\ZHONGZHENHUA\imooc\concurrency>git add ./src/main/java/mmall/concurrency/annoations/ThreadSafe.java fatal: pathspec './src/main/java/mmall/concurrency/annoations/ThreadSafe.java' did not match any filesC:\Users\ZHONGZHENHUA\imooc\concurrency>git add ./src/main/java/mmall/concurrency/annoations/ThreadSafe fatal: pathspec './src/main/java/mmall/concurrency/annoations/ThreadSafe' did not match any filesC:\Users\ZHONGZHENHUA\imooc\concurrency>git add .C:\Users\ZHONGZHENHUA\imooc\concurrency>git status On branch master Your branch is up-to-date with 'origin/master'.Changes to be committed:Changes to be committed:(use "git reset HEAD <file>..." to unstage)new file: src/main/java/com/mmall/concurrency/TestController.javanew file: src/main/java/com/mmall/concurrency/annoations/NotRecommend.javanew file: src/main/java/com/mmall/concurrency/annoations/NotThreadSafe.javanew file: src/main/java/com/mmall/concurrency/annoations/Recommend.javanew file: src/main/java/com/mmall/concurrency/annoations/ThreadSafe.javaC:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -am 'add annoations' fatal: Paths with -a does not make sense.C:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -am 'add annoations' fatal: Paths with -a does not make sense.C:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -a Aborting commit due to empty commit message.C:\Users\ZHONGZHENHUA\imooc\concurrency>git push Everything up-to-dateC:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -am 'add annoations' fatal: Paths with -a does not make sense.C:\Users\ZHONGZHENHUA\imooc\concurrency>git commit --am 'add annoations' error: pathspec ''add' did not match any file(s) known to git. error: pathspec 'annoations'' did not match any file(s) known to git.C:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -a 'add annoations' fatal: Paths with -a does not make sense.C:\Users\ZHONGZHENHUA\imooc\concurrency>git init Reinitialized existing Git repository in C:/Users/ZHONGZHENHUA/imooc/concurrency/.git/C:\Users\ZHONGZHENHUA\imooc\concurrency>git add .C:\Users\ZHONGZHENHUA\imooc\concurrency>git status On branch master Your branch is up-to-date with 'origin/master'.Changes to be committed:(use "git reset HEAD <file>..." to unstage)new file: src/main/java/com/mmall/concurrency/TestController.javanew file: src/main/java/com/mmall/concurrency/annoations/NotRecommend.javanew file: src/main/java/com/mmall/concurrency/annoations/NotThreadSafe.javanew file: src/main/java/com/mmall/concurrency/annoations/Recommend.javanew file: src/main/java/com/mmall/concurrency/annoations/ThreadSafe.javaC:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -am 'add annoations' fatal: Paths with -a does not make sense.C:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -m 'add annoations' error: pathspec 'annoations'' did not match any file(s) known to git.C:\Users\ZHONGZHENHUA\imooc\concurrency>git init Reinitialized existing Git repository in C:/Users/ZHONGZHENHUA/imooc/concurrency/.git/C:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -am 'add annoations' fatal: Paths with -a does not make sense.C:\Users\ZHONGZHENHUA\imooc\concurrency>git commit -am "add annoations" [master 751c061] add annoations5 files changed, 73 insertions(+)create mode 100644 src/main/java/com/mmall/concurrency/TestController.javacreate mode 100644 src/main/java/com/mmall/concurrency/annoations/NotRecommend.javacreate mode 100644 src/main/java/com/mmall/concurrency/annoations/NotThreadSafe.javacreate mode 100644 src/main/java/com/mmall/concurrency/annoations/Recommend.javacreate mode 100644 src/main/java/com/mmall/concurrency/annoations/ThreadSafe.javaC:\Users\ZHONGZHENHUA\imooc\concurrency>git push Counting objects: 14, done. Delta compression using up to 4 threads. Compressing objects: 100% (11/11), done. Writing objects: 100% (14/14), 1.36 KiB | 126.00 KiB/s, done. Total 14 (delta 4), reused 0 (delta 0) remote: Powered by Gitee.com To gitee.com:lvyinhaolaiwu/concurrency.git42a1cd3..751c061 master -> masterC:\Users\ZHONGZHENHUA\imooc\concurrency>?
轉(zhuǎn)載于:https://www.cnblogs.com/ZHONGZHENHUA/p/10033908.html
總結(jié)
以上是生活随笔為你收集整理的3-2 案例准备工作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 正规方程法
- 下一篇: 循环控制-链表反转(与创建链表)