Skip to content

Ban a spesific function/constructor #12975

Closed Answered by nrmancuso
VirtualTim asked this question in Q&A
Discussion options

You must be logged in to vote

@VirtualTim this should work for you:

➜  src cat Test.java 
public class Test {
    void inlineGood() {
        new Thread(new Runnable() {
            @Override
            public void run() {}
        }, "thread name").start();
    }

    void inlineBad() {
        new Thread(new Runnable() { // violation
            @Override
            public void run() {}
        }).start();
    }

    void goodThreads() {
        new Thread(m(), "thread name").start();
        new Thread(() -> m(), "thread name").start();
    }

    void badThreads() {
        new Thread(m()).start(); // violation
        new Thread(() -> m()).start(); // violation
    }

    Runnable m() {
        return System.ou…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@VirtualTim
Comment options

@romani
Comment options

Comment options

You must be logged in to vote
1 reply
@VirtualTim
Comment options

Answer selected by VirtualTim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants