我尝试在Junit测试用例中使用Springs自己的依赖注入:
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.binarisinformatik.api.AppConfig;
import org.binarisinformatik.satzrechner.SatzRechner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=AppConfig.class)
//@SpringApplicationConfiguration(classes = {AppConfig.class})
public class SatzRechnerTest {
@Autowired
private SatzRechner satzRechner; //SUT
@Before
public void setUp() {
// AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SatzRechnerTest.class);
//satzRechner=context.getBean(SatzRechner.class);
}
@Test
public void addiere_satz_4komma6_zu_zahlwert_10() {
assertThat("Addition von \"4,6\" ergibt nicht 10!",
satzRechner.summe("4,6"), is(equalTo(10)));
}
Run Code Online (Sandbox Code Playgroud)
我正在测试一个类名SatzRechner,其中Spring也应该自动装配一些变量.这是我的测试类:
@Component
public class SatzRechner {
@Autowired //@Inject
private Rechner taschenRechner; …Run Code Online (Sandbox Code Playgroud) 考虑重载函数foo:
fun foo(i: Int) { /* */ }
fun foo(i_s: Collection<Int>) { /* */ }
Run Code Online (Sandbox Code Playgroud)
我收到以下代码的重载解决方案歧义错误:
val bar = foo(Stream.empty<Int>().collect(Collectors.toList()))
Run Code Online (Sandbox Code Playgroud)
过载分辨率的歧义:
public fun foo(i:Int):在...中定义的单位
public fun foo(i_s:Collection):在...中定义的单位
据我所知,解决方案应该很明确:我正在将流收集到一个列表中,因此foo(Collection<Int>)应该采取。更多的实验表明无法正确解析泛型,因此:
我测试了其他几件事:foo(listOf())不会出错,也不会
val bar = Stream.empty<Int>().collect(Collectors.toList())
val baz = foo(bar)
Run Code Online (Sandbox Code Playgroud)
替换toList()为toSet()不会改变行为,但是toCollection { ArrayList<Int>() }在所有情况下都可以编译。
如果更改foo为fun <T> foo(i_s: Collection<T>),则错误更改为
类型推断失败。预期类型不匹配:推断的类型为(Mutable)List!但是Int被期望
这为我带来了更多问题:
在 Kotlin 中,该Number类型听起来非常有用:每当我需要数字时就可以使用的类型。
然而,当实际使用它时,我很快发现它毫无用处:我无法对这些数字使用任何运算符。一旦我需要对它们做一些事情,我就需要显式地转换它们(即使是为了比较)。
为什么语言设计者选择不在规范中包含运算符Number?
考虑到这一点,我注意到实现起来可能很棘手Number.plus(n: Number): Number,因为n可能与 属于不同的类型this。
另一方面,这样的实现确实存在于我检查的所有Number子类型中。当然,如果我想输入,它们是必要的1 + 1.2,这会调用Int.plus(d: Double): Double
.toDouble()对我来说,结果是每次使用号码时都必须拨打。这使得代码难以阅读(a.toDouble() < b.toDouble()与相比a < b)。
是否有任何技术原因导致运算符被省略Number?
我有一个SELECT A.ID, B.ID FROM A, B很好的查询。一旦添加FETCH FIRST n ROWS ONLY到它,查询就会失败并显示错误消息
SQL错误[918] [42000]:ORA-00918:列定义不明确
据我了解,该错误指的是不明确的SELECT子句,不应由引起FETCH FIRST n ROWS ONLY。
我会错过一些可以证明这种行为合理的东西吗?还是这是一个错误?
我知道在指定显式列别名时可以忽略此行为。我想知道,为什么SELECT A.ID, B.ID FROM A, B有效,而SELECT A.ID, B.ID FROM A, B FETCH FIRST 10 ROWS ONLY没有。
Oracle版本是12.1.0.2.0