java中reject方法作用_reject - 用于Java和Android的依赖注入框架

reject

Dependency Rejection for Java and Android

"Sometimes you have something that you don't want called. So you can simply annotate it with @Reject"

Dependency Rejection

Inspired by a comedy talk from Chet Haase and Romain Guy at droidcon London 2017 where they presented a "new programming language". The Functional And Reactive Turing-complete language.

The language comes with lots of useful features. One of them is dependency rejection. Such a helpful new feature shouldn't be limited to this particular language. reject ports the dependency rejection functionality and the @Reject annotation to Java and Android to make your projects clearer, simpler, and more productive.

reject gives you access to the @Reject annotation in your Java or Android project. It tells the compiler to reject certain things and it lets you know accordingly.

@Reject

public MyClass() { }

> gradle run

No.

Usage

Import the plugin

buildscript {

repositories {

jcenter()

}

dependencies {

classpath "com.mtramin.reject:gradle-plugin:"

}

}

apply plugin: 'reject'

Rejecting things

Simply annotate methods or constructors with the @Reject annotation to reject those.

public MyClass {

@Reject

public MyClass() {

System.out.println("Hello World")

}

@Reject

private void something() {

...

}

}

The compiler will then properly reject those classes/methods by simply saying "No.".

Samples

The samples showcase how to import reject and how to use it in Java and Android projects.

Java Sample

Run the Java sample with the following command and watch the output in the command line:

./gradlew :samples:sample-java:run

Android Sample

Build and run the sample application on an Android emulator or device and watch the logcat for the results.

Credits

Thanks to Chet Haase and Romain Guy for their comedy talk at droidcon London 2017. You can watch it here.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值