小编am5*_*a03的帖子

如何在用“冻结”库注释的类中添加自定义函数?

我定义了一个这样的类,并用冻结的库进行了注释。

@freezed
@immutable
abstract class CommentMediaAttachmentModel with _$CommentMediaAttachmentModel {
  const factory CommentMediaAttachmentModel({
    final String type,
    final String mediaUrl,
    final int width,
    final int height
  }) = _CommentMediaAttachmentModel;

  bool isAnimated() {
    return type == 'ANIMATED';
  } 
}
Run Code Online (Sandbox Code Playgroud)

我想添加一个快速函数isAnimated来确定type变量,但在编译时,它不允许我这样做:

lib/presentation/comment/model/comment_attachment_model.freezed.dart:292:7: Error: The non-abstract class '_$_CommentMediaAttachmentModel' is missing implementations for these members:
 - CommentMediaAttachmentModel.isAnimated
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or …
Run Code Online (Sandbox Code Playgroud)

dart flutter

9
推荐指数
1
解决办法
4702
查看次数

使用.getClass()被认为是一个糟糕的设计?

我目前正在实现一个函数,使用超类作为参数.

例如:

private void foo(Parent parent) {
    if(parent.getClass() == Child1.class) {
        Child1 c1 = (Child1) parent;
        System.out.println(c1.getChild1Attribute());
    }
    else if(parent.getClass() == Child2.class) {
        Child2 c2 = (Child2) parent;
        System.out.println(c1.getChild2Attribute());
    }
    else if(parent.getClass() == Parent.class) {
        System.out.println(parent.getParentAttribute());
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一个坏主意吗?

我在这里读到了一些线索,说使用getClass()或是instanceof不好的设计:

java oop

4
推荐指数
2
解决办法
661
查看次数

如何在 Android Studio 3.2 上查看实际的 Bitmap?

我知道有一个很好的功能,您可以在 Android Studio 3 之前从堆转储中查看实际的位图,但似乎没有了。 在此处输入图片说明

参考

/sf/answers/2866188741/

android-studio android-studio-3.0

3
推荐指数
1
解决办法
748
查看次数

标签 统计

android-studio ×1

android-studio-3.0 ×1

dart ×1

flutter ×1

java ×1

oop ×1