我想在kotlin中使用aspectj aop,这是我的代码:
我在annotation.lazy_list中的注释:
科特林:
package anotation
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class lazy_list
Run Code Online (Sandbox Code Playgroud)
我的方面是一个类:
@Aspect
class ActiveListAop{
@Pointcut("execution(@annotation.lazy_list * *(..))")
fun profile() {
}
@Before("profile()")
fun testModeOnly(joinPoint: JoinPoint) {
println("123")
}
}
Run Code Online (Sandbox Code Playgroud)
我的用法:
@lazy_list
fun all():List<T>{
return lazy_obj?.all() as List<T>
}
Run Code Online (Sandbox Code Playgroud)
当我调用all()函数,没有错误,但不打印"123",为什么?
我的实体类:
class User : ActiveRecord<User>() {
var name by Column(String.javaClass);
var id by Column(Int.javaClass);
}
Run Code Online (Sandbox Code Playgroud)
现在我想通过refelection设置名称值:
var clazz = User().javaClass
var record = clazz.newInstance()
var field = record.getDeclaredField(it + "$" + "delegate")
field.set(record, "aa")
Run Code Online (Sandbox Code Playgroud)
那么错误:
entity.Column字段ActiveRecord4k.User.name $委托给java.lang.String
这该怎么做?
例如,当我在Flutter中使用BLOC时:
class StreamText extends StatelessWidget {
StreamText(
this.stream, {
this.style,
});
final Stream<dynamic> stream;
final TextStyle style;
@override
Widget build(BuildContext context) {
return StreamBuilder<dynamic>(
stream: stream,
builder: (context, snapshot) {
return Text(snapshot.data.toString(), style: style);
},
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个无状态的小部件,dispose()那里没有方法。
以及当此小部件销毁时,我如何才能退出视频流或将自动退出视频流?
我的课:
class Demo {
init {
// define method here my some array:[a,b,c]
// such as fun Demo.a,Demo.b...
}
}
Run Code Online (Sandbox Code Playgroud)
函数名称是动态的。
Kotlin 可以做到这一点吗?
我可以转换"+","-"或"/"运营商使用2.send("-",3)
但它不起作用 "+="
a = 2
a += 2 #=> 4
a = 2
a.send("+=", 4) #=> NoMethodError: undefined method `+=' for 2:Fixnum
Run Code Online (Sandbox Code Playgroud)
我试图先转换符号; 但也行不通;
怎么解决这个问题?
这是我的功能:
operator infix fun List<Teacher>.get(int: Int): Teacher {
var t = Teacher()
t.name = "asd"
return t ;
}
Run Code Online (Sandbox Code Playgroud)
和我的用法:
b[0].teachers[1].name
Run Code Online (Sandbox Code Playgroud)
提示:b是具有List <Teacher>属性的对象
和错误Empty list doesn't contain element at index 1.
为什么这个覆盖操作员功能不起作用?
例如,我需要通过“this”获取组件对象,但“this”未定义
成分:
<Menu onClick ={()=>this.MenuNavigate()}/>
Run Code Online (Sandbox Code Playgroud)
原型函数:
React.Component.prototype.MenuNavigate = (e) => {
// let url = e.item.props["data-url"]
console.log(this)->undefined
}
Run Code Online (Sandbox Code Playgroud)
如何得到“这个”?
我认为所有组件都扩展了 React.Component,所以我想在所有扩展了 React.Component 的组件中使用函数,因为我不需要再次编写