class Test{
static void testCase_1(long l){System.out.println("Long");}
static void testCase_2(Long l){System.out.println("Long");}
public static void main(String args[]){
int a = 30;
testCase_1(a); // Working fine
testCase_2(a); // Compilation time error
//Exception - The method testCase_2(Long) in the type Test is not applicable for the arguments (int)
}
}
Run Code Online (Sandbox Code Playgroud)
testCase - 1:int - 长期正常工作
testCase - 2:int to L ong抛出异常
为什么testCase_2()方法抛出编译异常?
当我使用eclipse ID时,我突然发现我在变量声明中加了双分号.
以下是我的发言
double defaultValue = 0.0;;
Run Code Online (Sandbox Code Playgroud)
我在这里感到困惑.我期望上面的语句抛出一个异常,但我错误的上面的语句运行没有任何错误.
为什么双分号没有显示任何错误?
我试图拆分字符串作为下面的代码
String []data = {"3.5,2.3,4.2,5.4,7.4,2.7"};
String s[] = data.split("\\,");
double point3[] = new Double [s.length];
double allPoint[] = new double [s.length];
for (int i = 0; i < s.length; i++){
point3[2] = Double.parseDouble(s[2]);
//lng[i] = Double.parseDouble(s[i]);
allPoint[i] = Double.parseDouble(s[i]);
}
Run Code Online (Sandbox Code Playgroud)
我也试过data.split(","); 但问题不是反斜杠,它给出错误,split提示显示
找不到符号,符号:方法split(String)
我无法导入split
我现在可以做的事情.
我正在比较两个值并得到声纳棉绒投掷"Only the sign of the result should be examined" this issue。
代码 :
if (recBalanceAmt.compareTo(recRolloverEligibility) == 1) {
recExpAmt = recBalanceAmt.subtract(recRolloverEligibility);
}
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
我使用下面的代码,并根据逻辑使用了两个continue语句,但声纳列表显示了此问题 Reduce the total number of break and continue statements in this loop to use at most one.
如何解决这个问题?
for (HashMap<String, String> objRequestIdVO : pObjTicketId) {
List<TicketDetailsDO> objTicketDetailslist = storeManagerDao.getTicketDetailsWithTicketId(objRequestIdVO.get("requestId"));
if (null == objTicketDetailslist || objTicketDetailslist.isEmpty()) {
continue;
}
Integer iDesiredDsicount = objTicketDetailslist.get(0).getDesiredDiscount();
String iSubDept = objTicketDetailslist.get(0).getSubdeptTicket().getSubDeptId();
List<MCouponDO> objMCounponList = storeManagerDao.getMcouponData(iDesiredDsicount, iSubDept);
if (null == objMCounponList || objMCounponList.isEmpty()) {
continue;
}
String strHeader = objMCounponList.get(0).getHeader();
objHeaderVO = new HeaderVO();
objHeaderVO.setHeader(strHeader);
objHeaderVO.setRequestId(objRequestIdVO.get("requestId"));
objHeaderVOList.add(objHeaderVO);
}
Run Code Online (Sandbox Code Playgroud) 当覆盖方法然后面临一个问题:
public interface IProduct {
public void sendMessage(Object object);
}
@Service
public class ProductManagere implements IProduct{
@Override
public void sendMessage(Product product) {
// Added logic
}
}
Run Code Online (Sandbox Code Playgroud)
但要低于例外:
ProductManagere类型的sendMessage(Product)方法必须覆盖或实现超类型方法
我不明白为什么抛出这个例外.我希望product是Object的子类型,所以它不会抛出异常.
首先,我需要检查列表中是否存在数据,然后在Java 8流上获取其他设置的默认值或空值.
目前我使用下面的代码,isPresent但我不知道如何在java8中使用isPresent.
我正在尝试下面不完美的东西:
String isScheme = (this.mapProgramApproaches.stream().findFirst().isPresent())? this.mapProgramApproaches.stream().findFirst().get().getIsScheme().toString() : "0";
Run Code Online (Sandbox Code Playgroud)
凡为mapProgramApproaches这个设置.
我正在将整数对象与原始int进行比较,但是如果Integer对象是,则会得到空指针异常 null
public static void main(String[] args) {
Integer a = null;
int b = 1;
if (a != b) {
System.out.println("True");
}
}
Output : Exception in thread "main" java.lang.NullPointerException
at com.nfdil.loyalty.common.Test.main(Test.java:10)
Run Code Online (Sandbox Code Playgroud)
我得到这个是因为它试图转换null integer object (a.intValue()) into primitive int。
还有其他方法可以避免这种情况吗?