* * @author: Jack * 2021/3/16 上午11:18 * * 1.Kotlin中的元注解类定义于kotlin.annotation包中,主要有: @Target、@Retention...1、Kotlin注解声明 package com.mikyou.annotation //和一般的声明很类似,只是在class前面加上了annotation修饰符 annotation class TestAnnotation...Kotlin中的元注解类定义于kotlin.annotation包中,主要有: @Target、@Retention、@Repeatable、@MustBeDocumented 4种元注解相比Java中...2、源码定义 @Target(AnnotationTarget.ANNOTATION_CLASS)//可以给标签自己贴标签 @MustBeDocumented //注解类构造器参数是个vararg不定参数修饰符...//运行时期(RUNTIME): 注解会存储出class字节码中,也会对反射可见, 默认是RUNTIME } @MustBeDocumented元注解 1、介绍 该注解比较简单主要是为了标注一个注解类作为公共
Benz() "Audi" -> return Audi() } } } 复制代码 看起来非常完美,使用了工厂模式,很高级,需要生产什么牌子的车,直接传一个品牌名字就可以生产出对应牌子的汽车了...getSupportedAnnotationTypes() 方法,返回要处理哪些自定义注解,也可以使用 @SupportedAnnotationTypes() 它的返回值是 process() 方法的第一个参数...如果你是 kotlin 工程,请使用 kapt {your_porcessor_module} 的方式依赖,且需要依赖 kapt gradle 插件 apply kotlin-kapt 如果你是 Java...roundEnvironment.processingOver() 判断是否第一次执行 process() : processingOver 为 false 代表第一次执行 4.有时候我们想要拿到注解中的参数...,如果这个参数刚好是 Class 类型的,在 process() 方法中尝试获取换个 Class 对象的时候会发生错误,这是因为 Annotation Processor 在执行的时候这个类可能还没有参与编译
随着响应式编程越来越受欢迎,我们可以期待越来越多的技术将实现响应式解决方案。...在Java 8里,任何函数式接口作为方法的参数传入或者作为方法返回值的场合,都可以用Lambda表达式代替。...在Java 8中我们可以写一个lambda表达式作为第二个参数的值传进去。.../spring-beans/src/test/kotlin/org/springframework/beans/factory/annotation/KotlinAutowiredTests.kt ..../spring-context/src/test/kotlin/org/springframework/context/annotation/Spr16022Tests.kt .
SimpleRouter.getInstance() .build("/app/demo/profile") .withString("name", "app-profile:透传参数...floatSimpleRouter.getInstance() .build("/app/demo/profile") .withString("name", "app-profile:透传参数...demo/profile") .withBundle(Bundle().apply { putString("name", "app-profile:透传参数...SimpleRouter.getInstance() .build("/app/demo/product") .withString("name", "app-product:透传参数...intentSimpleRouter.getInstance() .build("/app/demo/product") .withString("name", "app-product:透传参数
注解是将元数据附加到代码的方法。...它们是:类 CLASS, 注解类 ANNOTATION_CLASS,泛型参数 TYPE_PARAMETER,函数 FUNCTION, 属性 PROPERTY, 用于描述域成员变量的 FIELD,局部变量...类型 以上所有引用类型的数组(注意,不包括基本数据类型) 例如下面的都是合法的注解构造函数的参数类型 annotation class TestCase(val id: String) annotation...不支持将null作为注解属性的值存储。...如果注解用作另一个注解的参数,其名称不以@字符为前缀 annotation class AnnoX(val value: String) annotation class AnnoY(
本文将列举这些解决方案,包括传统的空值检测、编程规范、以及使用现代 Java 语言引入的各类工具来作为辅助。...arg) { System.out.println(arg.toString()); } public void testArgumentNonNull() { // 错误:不能将 null 传递给非空参数...Kotlin 支持的 注解 也非常广泛。...Spring Framework 5.0 起原生支持 Kotlin,其空值检测也是通过注解进行的,使得 Kotlin 可以安全地调用 Spring Framework 的所有 API。...如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
WorkSpace\001_AS\Coroutine> gradlew app:dependencies --configuration releaseRuntimeClasspath gradlew : 无法将“...所在位置 行:1 字符: 1 PS Y:\002_WorkSpace\001_AS\Coroutine> gradlew gradlew : 无法将“gradlew”项识别为 cmdlet、函数、脚本文件或可运行程序的名称...| | +--- androidx.annotation:annotation-experimental:1.3.0 | | | \--- org.jetbrains.kotlin...:annotation:1.1.0 -> 1.3.0 | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*...| \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*) | +--- androidx.annotation:annotation
Kotlin 版本到 1.7.10 直接将 工程根目录 中 build.gradle 构建脚本的 Kotlin 版本提升到 1.7.10 ; // Top-level build file where...:annotation:1.1.0 -> 1.3.0 | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*...| \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*) | +--- androidx.annotation:annotation...:annotation:1.0.0 -> 1.3.0 | +--- androidx.annotation:annotation-experimental:1.0.0 -> 1.1.0 |...:annotation:1.1.0 -> 1.3.0 | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*
/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin...Kotlin 版本到 1.7.10 直接将 工程根目录 中 build.gradle 构建脚本的 Kotlin 版本提升到 1.7.10 ; // Top-level build file where...| | +--- androidx.annotation:annotation-experimental:1.3.0 | | | \--- org.jetbrains.kotlin...:annotation:1.1.0 -> 1.3.0 | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*...| \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*) | +--- androidx.annotation:annotation
println("Hello, ${name}"); } } fun main(args: Array) { Greeter(args[0]).greet() } 构造函数传参...初始化的代码可以被放置在initializer blocks(初始的模块),以init为前缀作为关键字{:.keyword} class Customer(name: String) { init...,编译器会产生一个额外的参数的构造函数,将使用默认值。...这使得更易于使用kotlin与通过参数构造函数创建类的实例,如使用Jackson或JPA库的时候。...更具体地讲,如果你声明一个同伴对象在你的的类中, 你就可以在Java/ C#中调用与它的成员方法相同的语法的静态方法,只使用类名作为一个修饰语。
:annotation:1.1.0 -> 1.3.0 | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 |...:kotlin-stdlib:1.6.20 -> 1.7.10 (*) | | | +--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 ->...:kotlin-stdlib-jdk8:1.6.0 | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:...| \--- org.jetbrains.kotlin:kotlin-stdlib:1.6.21 -> 1.7.10 (*) | +--- androidx.annotation:annotation...构建工具选择生效的依赖版本 , androidx.appcompat:appcompat:1.1.0 版本的依赖作废 , 使用 androidx.appcompat:appcompat:1.5.1 版本的依赖作为正式版本
前言 本章将讲解一些管对对象和基础编程的知识。如:类,接口,抽象类,数据类,扩展方法等 接口 其实这部分的设计思路和Java基本一致。...返回值类型不能作为方法签名的一部分 只有参数列表和方法名 重载时如果不能用默认参数解决的重载 不是一个好的设计 例如 list.remove 默认参数 可以参数 不传参数用默认值 这个方法java要调用...需要加上 @JvmOverloads否则必须传参数 扩展方法 为现有类添加方法、属性: fun X.y):Z{..} val X.m 注意扩展属性不能初始化,类似接口属性 Java 调用扩展成员类似调用静态方法...下build.gradle apply plugin: 'kotlin-noarg' apply plugin: 'kotlin-allopen' noArg { annotation("...,或者作为它的内部类。
可以这么说元编程是更高阶的抽象,高阶函数用函数作为输入输出。而元编程用程序作为输入输出。...再来看下Kotlin中的反射结构: Kclass代表类信息,Kparameter代表参数信息,而KCallable和Accessible一样代表的都是可调用的元素。...注解处理器 Kotlin中的注解处理器和Java中的一样,注解参数为常量,作用范围为: 基本类型 字符串 Class对象 注解 类型数组,XXXArray 定义方式:比Java中更明显:用annotation...缺点 虽然annotation processor允许开发人员访问程序AST(抽象语法树可查看之前文章JVM编译只是),但没有提供行之有效的代码生成方案,目前仅有的代码生成方案也仅仅是将代码以字符串的形式写入新文件...,而无法做到直接将生成的AST作为程序。
使用 Spring Boot 开发,对外开发接口供调用,传入参数中有中文,出现中文乱码,查了好多资料,总结解决方法如下: 第一步,约定传参编码格式 不管是使用httpclient,还是okhttp,都要设置传参的编码...27606769/how-to-overwrite-stringhttpmessageconverter-default-charset-to-use-utf8-in-sprin package com.kotlin.springboot.nextj2ee.config...import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration...org.springframework.http.converter.StringHttpMessageConverter import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer...import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter import java.nio.charset.StandardCharsets
换了kotlin以后,好像不行了,于是我用了土方法。...如果在某个类中声明一个同伴对象, 那么只需要使用类名作为限定符就可以调用同伴对象的成员了, 语法与Java中调用类的静态方法、静态变量一样。...这个框架的saf-router-compiler模块是用kotlin编写的。...使用方法 Activity跳转 它支持Annotation方式和非Annotation的方式来进行Activity页面跳转。...q=31,121"); 总结 最后,使用这个框架是不需要先有的程序去配置Kotlin的环境的。 未来,会考虑把这个项目的其余模块也都用Kotlin来编写,以及新功能的开发。
10.2.3' 注解处理器 , 然后到 com.jakewharton:butterknife-compiler:10.2.3 注解处理器中查找相关的注解处理的类 ; 使用编译时技术 APT 时 , 一般将...--- 使用 Android Studio 开发 Android 项目时 , 使用到编译时技术 , 都要用到 编译时注解 和 注解处理器 ; 编译时注解 和 注解处理器 一般都创建为 Java or Kotlin...Library ; 设置依赖库名称 , 注意语言选择 Java ; 暂时不涉及 Kotlin 注解 ; 使用上述相同的方式 , 创建 annotation 编译时注解 依赖库 和 annotation-compiler...注解处理器 依赖库 , 这两个 Module 的类型都是 " Java or Kotlin Library " ; 三、添加 编译时注解 和 注解处理器 依赖库依赖 ---- 在主应用 " app...Structure " 对话框中选择 " Dependencies " 选项卡 , 选择主应用 " app " , 点击 " + " 按钮 , 选择添加 " Module Dependency " 依赖库 , 将
比最成熟的竞争者Scala还简单 Kotlin不像Scala另起炉灶,将类库,尤其是集合类都自己来了一遍。...import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping...import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.ResponseBody...SpringBoot的启动类: 我们用Kotlin写SpringBoot的启动类: ``` package com.restfeel import org.springframework.beans.factory.annotation.Autowired...; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention
--《Kotlin in Action》 注解(也被成为元数据)为我们在代码中添加信息提供了一种形式化的方法,使我们可以在稍后某个时刻非常方便地使用这些数据。...MyAnnotation2{ String value(); } Kotlin: annotation class MyAnnotation annotation class MyAnnotation2...KAPT与APT完全相同,只是在Kotlin下的注解处理器。 实例 使用编译时注解+APT+动态生成字节码完成了一个butterKnife最基础的findViewById的功能,适合入门学习。...getAllMembers(typeElement) //创建一个bingdView的方法,参数为activity,并使用JvmStatic注解 val...mLogger.info("end") return true } 编译代码,本例就会在build下生成一个MainActivity_bindView的类,其中有一个静态方法bindview,传入的参数是
} } 5.本地化配置类 LocaleConfig.kt package com.example.i18ndemo import org.springframework.context.annotation.Bean...import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.LocaleResolver...import org.springframework.web.servlet.config.annotation.InterceptorRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer...sessionLocaleResolver.setTimeZoneAttributeName("GMT+8") return sessionLocaleResolver } /** * 默认拦截器,其中lang表示切换语言的参数名...5.默认和命名参数 在Kotlin中,您可以为函数中的参数设置一个默认值,并给每个参数一个名称。这有助于编写易读的代码。
该注解提供了许多参数,包括允许访问的来源、方法、头部等。...以下是一个示例:kotlin 代码解读复制代码import org.springframework.web.bind.annotation.CrossOrigin;import org.springframework.web.bind.annotation.GetMapping...;import org.springframework.web.bind.annotation.RestController;@RestController@CrossOrigin(origins =...@GetMapping("/api/data") public String getData() { // 处理请求逻辑 }}在上述示例中,@CrossOrigin注解将允许来自任意服务器的跨域请求访问...以下是一个示例:kotlin 代码解读复制代码import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.CorsRegistry