The parameter 'foo' should not be assigned — what's the harm?

前端 未结 5 459
感动是毒
感动是毒 2020-12-17 08:52

Compare this method:

void doStuff(String val) {
    if (val == null) {
        val = DEFAULT_VALUE;
    }

    // lots of complex processing on val
}
         


        
5条回答
  •  难免孤独
    2020-12-17 09:27

    There is a compiler preference which dictates whether or not an instance of parameter assignment is ignored, flagged with a warning, or flagged with an error.

    Go to the menu bar - choose Window..Preferences, then In the tree control of the Preferences dialog, select Java..Compiler..Errors/Warnings, then Look in the Code Style section for the "Parameter Assignment" setting.

    alt text

提交回复
热议问题