在Kotlin中,如果对象不是null,我可以运行代码:
data?.let {
... // execute this block if not null
}
Run Code Online (Sandbox Code Playgroud)
但如果对象为null,我该如何执行代码块?
在Flutter中,可以使用ThemeData类将主题应用于应用程序.但是这个课程有两个让我困惑的事情:primaryColor和primarySwatch.这两个属性之间的区别是什么,何时使用其中一个?谢谢.
我正在尝试使用 kotlin 实现视图模型。首先,我添加了所需的依赖项:
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0"
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个简单的视图模型:
class MyViewModel: ViewModel() {
val greeting = "Hello World"
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用 kotlin 属性委托从活动访问视图模型时:
val model by viewModels<MyViewModel>()
Run Code Online (Sandbox Code Playgroud)
编译器不解析viewModels. 我不知道是什么问题。我错过了什么?
我已将TextView设置为显示.我想在一行中显示正在执行的操作,例如:
9856243187 + 2457896123 - 214583
Run Code Online (Sandbox Code Playgroud)
问题是,当输入到达TextView的边缘时 - 它会跳转到下一行.
那么,无论如何都要避免这种行为,并将输入保持在一行中,即使它离开了屏幕?
使用'logt','logd','loge'等快捷方式在Intellij中记录Java非常简单.但我搬到Kotlin,我注意到那些快捷方式不再适用了.我不知道它是否与我的配置有关,但如果没有,我该如何解决这个问题呢?
Flutter是一个简单易用的惊人框架.我必须看到文档非常好,但有一些概念对我来说仍然含糊不清,例如key参数.根据文档A Key is an identifier for Widgets, Elements and SemanticsNodes.很清楚,但为什么我需要识别我的小部件.到目前为止,我从未在编码中使用过键.在我的代码中使用密钥有什么好处吗?谢谢.
我知道当使用父类引用来引用子类对象时,OOP中多态性的常见用法是这样的:
Animal animal = new Animal();
Animal dog = new Dog();
Run Code Online (Sandbox Code Playgroud)
我知道多态性适用于类方法,但它是否也适用于类属性?我尝试用这个小例子来测试它:
public class Main{
public static void main(String args[]){
Animal animal = new Animal();
Animal dog1 = new Dog();
Dog dog2 = new Dog();
System.out.println("Animal object name: " + animal.name);
System.out.println("Dog1 object name: "+dog1.name);
System.out.println("Dog2 object name: " + dog2.name);
animal.print();
dog1.print();
dog2.print();
}
}
class Animal{
String name = "Animal";
public void print(){
System.out.println("I am an: "+name);
}
}
class Dog extends Animal{
String name = "Dog";
public …Run Code Online (Sandbox Code Playgroud) 关于Flutter 的Google I/O 2018 视频介绍了如何使用Dart流来管理Flutter应用程序中的状态.该发言者谈到了使用Sink输入流和Stream输出流.Sink和之间有什么区别Stream?我搜索了文档,但它没有说太多的谢谢.
我正在阅读这个很棒的教程,解释了@Component.BuilderDagger 2中的工作方式.作者做得很好,文章很简单,但我仍需要澄清一些令人困惑的事情:Dagger 2的默认实现看起来像这样:
组件:
@Singleton
@Component(modules = {AppModule.class})
public interface AppComponent {
void inject(MainActivity mainActivity);
SharedPreferences getSharedPrefs();
}
Run Code Online (Sandbox Code Playgroud)
模块:
@Module
public class AppModule {
Application application;
public AppModule(Application application) {
this.application = application;
}
@Provides
Application providesApplication() {
return application;
}
@Provides
@Singleton
public SharedPreferences providePreferences() {
return application.getSharedPreferences(DATA_STORE,
Context.MODE_PRIVATE);
}
}
Run Code Online (Sandbox Code Playgroud)
组件实例化:
DaggerAppComponent appComponent = DaggerAppComponent.builder()
.appModule(new AppModule(this)) //this : application
.build();
Run Code Online (Sandbox Code Playgroud)
根据文章,我们可以通过避免使用@Component.Builder和@BindsInstance注释向模块构造函数传递参数来进一步简化此代码,然后代码将如下所示:
组件:
@Singleton
@Component(modules = {AppModule.class})
public interface AppComponent …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的vue-cli-3项目中包含一个cdn外部css文件,所以我在文件中添加了css文件,public/index.html如下所示:
<link rel="stylesheet" href="http://mycssfile.css">
Run Code Online (Sandbox Code Playgroud)
但是css不包含在生成的index.html文件中.这曾经在vuejs2中工作,我不明白为什么它不适用于vuejs3.知道问题是什么吗?谢谢