2

I was using a the reviewer "codePro Tools" by google and it flagged the flowing:

new Object[] { max }

with "Statically initialized array"

Explanation:

An array initializer is being used to initialize an array.

Recommendation

  1. The array should be initialized dynamically.

are there a good reason for this? or is just better to ignore.

this flag is on a section of rules called "code style".

Thanks

5
  • 1
    I use static initialisers frequently. I believe that in certain situations they can make structures clearer. Commented Sep 27, 2011 at 10:00
  • Does it go away when you declare the variable final? Commented Sep 27, 2011 at 10:05
  • @michael667 I assume not looking at the doc: code.google.com/javadevtools/codepro/doc/features/audit/… Commented Sep 27, 2011 at 10:19
  • final Object[] var = new Object[] { max }; nope flagged as well. Commented Sep 27, 2011 at 10:20
  • Well rule disabled... after listen your opinions. I just want to be sure i wasn't missing anything Commented Sep 27, 2011 at 10:32

2 Answers 2

4

As always: it depends. It's a question of style. I personally can't see anything wrong with this at all. In this case, I think it would just obscure the code to initialise it dynamically.

I use statically initialized arrays all of the time. Code style is very subjective and varies from project to project, not just from person to person. It's up to you to decide whether it's a good thing for your project.

Sign up to request clarification or add additional context in comments.

Comments

2

Take all automated code inspection tools with a grain of salt. They make recommendations, not issue commands.

If you have a good reason for writing your code that way, and can articulate it well to yourself and others, then stick with your code and ignore CodePro.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.