2016-09-23 56 views
0

这是代码。方法test和test2中的代码是不同的,因为传递给Test构造函数的参数是不同的。实际上,如果我将任何参数更改为null,intellij将停止报告重复。有没有什么办法解决这一问题?Intellij报告代码重复,而实际上它不是

----更新--------

我经过2个功能做完全不同的事情,但仍的IntelliJ重复报告

public class TestMain { 

    public void test(int a) 
    { 
     System.out.println("haha"); 
     System.out.println("hahaa"); 
     TestMain testMain = new TestMain(); 
     new Test(testMain::test3); 
     System.out.println("hahaaa"); 
    } 

    public void test2(int a) 
    { 
     System.out.println("haha"); 
     System.out.println("hahaa"); 
     TestMain testMain = new TestMain(); 
     new Test(testMain::still_dup); 
     System.out.println("hahaaa"); 
    } 

    public void test3(int a) { 
     System.out.println("abc"); 
    } 

    public void still_dup(int a) { 
     String b = "edf"; 
     b.toLowerCase(); 
    } 

    public class Test { 
     Test(handler h) { 

     } 
    } 

    public interface handler<M> { 
     void entitySelector(int a); 
    } 

    public static void main(String[] args) { 
     TestMain test = new TestMain(); 
     test.test(1); 
     System.out.println("-------"); 
     test.test2(2); 
    } 
} 
+0

您传递了两个不同的方法引用,但两个引用的方法完全相同。 –

+0

@JBNizet这不是重点。即使我通过一个完全不同的功能,它也报告重复。 – Cuero

回答

0

我认为最好的方式来解决,这是用一种方法替代testtest2。您不必区分传递构造函数的内容,因为它是当前的方法。这可能是报告代码重复的原因。这些方法可以被一个单一的方法替代而没有问题。

+0

“单一方法”是什么意思? – Cuero

+0

我的意思是用一种方法替换两种方法。 – mm759

+0

答案不再适用,因为问题已更新。在test和test2中传递的方法引用已更改。 – mm759

相关问题