English 中文(简体)
主张 平等工作,无第二参数
原标题:assertEquals doesn t work without second parameter casting
  • 时间:2010-10-29 14:11:00
  •  标签:
  • java
  • junit

土库斯,为什么我拿到“方法主张(标准、目标、目标)”这一日特尼特测试的“理论试验”错误不明确?

@Test
 public void testEditCard() {
  Integer a = 10;
  Integer b = 12;
  Integer c = 2;
  assertEquals("test", a-b, c);
 }

添加以下文字:assertEquals(”test”,(Integer)(a-b),c); 解决问题。

最佳回答

由于汽车箱和零箱的奇迹:

assertEquals("test", /* this is an int */ a-b, /* this is an Integer */ c);

能够评价

assertEquals(String, long, long);
// in this case the second parameter is unboxed
// (and the first one silently casted)

assertEquals(String, Object, Object);
// in this case the first parameter is boxed

如果你宣布所有变量为隐蔽(而不是 Integer),就不应含糊不清。

问题回答

这是因为汇编者可以告诉你是否希望打上<条码>。 由于a-bc可自动胁迫至long,汇编者看到了一个模糊之处。

你明确告诉汇编者,你想要的是目标版本。

请注意,在这种情况下,你可以使用<代码>int而不是Integer变量,这些变量也将确定模棱两可之处。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签