What is the reason for these PMD rules?

后端 未结 6 812
滥情空心
滥情空心 2020-12-01 04:41

DataflowAnomalyAnalysis: Found \'DD\'-anomaly for variable \'variable\' (lines \'n1\'-\'n2\').

DataflowAnomalyAnalysis: Found \'DU\'-anomaly

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 04:55

    Wouldn't setting an object to null assist in garbage collection, if the object is a local object (not used outside of the method)? Or is that a myth?

    The only thing it does is make it possible for the object to be GCd before the method's end, which is rarely ever necessary.

    Are there any advantages to using final parameters and variables?

    It makes the code somewhat clearer since you don't have to worry about the value being changed somwhere when you analyze the code. More often then not you don't need or want to change a variable's value once it's set anyway.

    If I know that I specifically need a LinkedList, why would I not use one to make my intentions explicitly clear to future developers?

    Can you think of any reason why you would specifically need a LinkedList?

    It's one thing to return the class that's highest up the class path that makes sense, but why would I not declare my variables to be of the strictest sense?

    I don't care much about local variables or fields, but if you declare a method parameter of type LinkedList, I will hunt you down and hurt you, because it makes it impossible for me to use things like Arrays.asList() and Collections.emptyList().

    What advantages does block-level synchronization have over method-level synchronization?

    The biggest one is that it enables you to use a dedicated monitor object so that only those critical sections are mutually exclusive that need to be, rather than everything using the same monitor.

    in the Java world, why should I not use the type that best describes my data?

    Because types smaller than int are automtically promoted to int for all calculations and you have to cast down to assign anything to them. This leads to cluttered code and quite a lot of confustion (especially when autoboxing is involved).

提交回复
热议问题