小编Ine*_*ego的帖子

什么是ngrx中的store.select

我是Redux的新手,从ngrx开始.我无法理解这行代码的含义store.select:

 clock: Observable<Date>;
 this.clock = store.select('clock');
Run Code Online (Sandbox Code Playgroud)

javascript redux ngrx angular

24
推荐指数
2
解决办法
2万
查看次数

从超级模式(棉花糖)继承“排除”元参数

我有一个对象层次结构和一个对应于它们的模式层次结构。此层次结构的中间级别的架构不包括特定的继承字段。我希望从它继承的模式会“继承”这个排除,但如果他们在他们的 Meta 类中添加自己的排除字段,情况似乎并非如此:

from marshmallow import fields
from marshmallow.schema import Schema


class AncestorSchema(Schema):
    a = fields.Str()
    b = fields.Str()


class IntermediateSchema(AncestorSchema):
    c = fields.Str()

    class Meta:
        exclude = ('b',)


class FinalSchema(IntermediateSchema):
    d = fields.Str()

    class Meta:
        exclude = ('c',)


value = dict(
    a="Field A",
    b="Field B",
    c="Field C",
    d="Field D"
)

print(IntermediateSchema().dump(value).data)

>>> {'c': 'Field C', 'a': 'Field A'}

print(FinalSchema().dump(value).data)

>>> {'d': 'Field D', 'a': 'Field A', 'b': 'Field B'}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,FinalSchema继承自IntermediateSchema(排除 field b)并排除c其自己 …

marshmallow

5
推荐指数
1
解决办法
2395
查看次数

从上下文得知接收者时,缩短了对类方法的引用

在以下代码中,

class IncWrapper<T> (val wrapped: T, val base: Int) {
    fun incFunction(increment: Int, func: T.(Int) -> Int): Int {
        return increment + wrapped.func(base)
    }
}

class ClassWithIndecentlyLongName {
    fun square(x: Int) = x * x
}

fun main() {
    val wrapper = IncWrapper(ClassWithIndecentlyLongName(), 2)
    val computed = wrapper.incFunction(1, ClassWithIndecentlyLongName::square)
    println(computed)
}
Run Code Online (Sandbox Code Playgroud)

我们传递了对包装类方法的引用ClassWithIndecentlyLongName。由于在调用站点上知道此类应作为方法的接收者,因此再次传递该类的名称似乎很尴尬/多余。我希望有些事情::square能奏效,但事实并非如此。如果缺少此功能,可能是什么原因?

(这个问题源于试图重构一些冗长的Java代码,将一类的许多字段转换为另一类的代码。)

type-inference kotlin method-reference

5
推荐指数
1
解决办法
46
查看次数

jit会优化新对象吗?

我创建了这个类是不可变的,并且具有流畅的API:

public final class Message {
    public final String email;
    public final String escalationEmail;
    public final String assignee;
    public final String conversationId;
    public final String subject;
    public final String userId;

    public Message(String email, String escalationEmail, String assignee, String conversationId, String subject, String userId) {
        this.email = email;
        this.escalationEmail = escalationEmail;
        this.assignee = assignee;
        this.conversationId = conversationId;
        this.subject = subject;
        this.userId = userId;
    }

    public Message() {
        email = "";
        escalationEmail = "";
        assignee = "";
        conversationId = "";
        subject = …
Run Code Online (Sandbox Code Playgroud)

java jit fluent immutability compiler-optimization

4
推荐指数
1
解决办法
676
查看次数

Jooq如何基于复合键查询实体

如何在Jooq中基于复合键查询实体?例如:

UserAttempts org.jooq.impl.DAOImpl.findById(Record2<UInteger, String> id)
Run Code Online (Sandbox Code Playgroud)

id是一个复合键.怎么用Record2<UInteger, String>

java sql composite-key jooq

4
推荐指数
1
解决办法
1151
查看次数

返回和内联

我试图找到与此Java返回相当的Kotlin:

return new int[] {1, 2, 3};
Run Code Online (Sandbox Code Playgroud)

我试过只是声明然后像这样返回:

val returnArr: IntArray = intArrayOf(1, 2, 3)
return returnArr
Run Code Online (Sandbox Code Playgroud)

但是我收到一条警告,上面写着"变量仅用于跟随返回并且可以内联".内联究竟是什么意思?有没有办法在一条线上完成所有这些?

java kotlin

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

将字段限制为类的实例并同时实现接口

Java允许将子类实例分配给类类型字段,例如:

public class BaseClass {

}

public class SubClass extends BaseClass {

}

public class Example {

    private BaseClass field1;

    public void assign(SubClass subclass) {
        field1 = subclass; // is OK
    }

}
Run Code Online (Sandbox Code Playgroud)

Java还允许将接口用作类型.如果我们有一个界面Fooable,

public interface Fooable {
    void foo();
}
Run Code Online (Sandbox Code Playgroud)

我们Example班可以有一个类型的领域Fooable,

    Fooable field2;
Run Code Online (Sandbox Code Playgroud)

也就是说,可以分配给field2实现Fooable接口的任何类的实例.

但是如果我想告诉编译器field3必须同时是接口的实例BaseClass和实现Fooable呢?所以,如果有一个班级

public class FooSubClass extends BaseClass implements Fooable {
    @Override
    public void foo() {
        // TODO
    } …
Run Code Online (Sandbox Code Playgroud)

java oop

2
推荐指数
1
解决办法
77
查看次数