我有一个叫做的课Pin
.
public class Pin
{
private string title;
public Pin() { }
public setTitle(string title) {
this.title = title;
}
public String getTitle()
{
return title;
}
}
Run Code Online (Sandbox Code Playgroud)
从另一个类我在引脚中添加Pins对象,从另一个类我List<Pin>
想迭代List引脚并获取元素.所以我有这个代码.
foreach (Pin obj in ClassListPin.pins)
{
string t = obj.getTitle;
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,我无法检索标题.为什么?
(注意:ClassListPin
只是一个包含一些元素的静态类,其中一个是List<Pin>
引脚)
我们如何使用 Koin 为 ViewModel 注入依赖项?
所以例如,我有一个ViewModel
这样的:
class SomeViewModel(val someDependency: SomeDependency, val anotherDependency: AnotherDependency): ViewModel()
Run Code Online (Sandbox Code Playgroud)
现在这里的官方文档指出,要提供一个ViewModel
我们可以执行以下操作:
val myModule : Module = applicationContext {
// ViewModel instance of MyViewModel
// get() will resolve Repository instance
viewModel { SomeViewModel(get(), get()) }
// Single instance of SomeDependency
single<SomeDependency> { SomeDependency() }
// Single instance of AnotherDependency
single<AnotherDependency> { AnotherDependency() }
}
Run Code Online (Sandbox Code Playgroud)
然后注入它,我们可以这样做:
class MyActivity : AppCompatActivity(){
// Lazy inject SomeViewModel
val model : SomeViewModel by viewModel()
override fun …
Run Code Online (Sandbox Code Playgroud) 我有两个EnumSet
.
EnumSet.of(A1, A2, A3);
EnumSet.of(A3, A4, A5, A6);
Run Code Online (Sandbox Code Playgroud)
我想找到两个集合中存在哪些值.(在这种情况下,A3
.)
有没有快速的方法呢?