昨天写了一篇PermissionsDispatcher初探,文章最后说要用java重写processor模块,今天花了半天时间完成,现在把代码放在github上:https://github.com/ileelay/PermissionsDispatcher/tree/2.2.0j,欢迎大家纠正!同时感慨到Kotlin太强大,Java太繁琐;
虽然Kotlin语法很简练,终究还是基于JVM,同时这篇文章不是循序渐进的Kotlin语法讲解,只是为了记录在转PermissionsDispatcher时的粗略见解;
普通class
kotlin是这样子写的
class NoParametersAllowedException(e: ExecutableElement) : RuntimeException("Method '${e.simpleString()}()' must not have any parameters")
为了保持参数一致,我用java是这样写的:
public class NoParametersAllowedException extends RuntimeException {
public static RuntimeException getInstance(ExecutableElement e) {
return new NoParametersAllowedException("Method "+e.getSimpleName().toString()+" must not have any parameters");
}
private NoParametersAllowedExce