0

I have a function like this

public static <
    T,
    X>
void helloFunction(T t, X x) {
  //some code here...
};

Assume that T and X are long words which why I have to add them on separated line. Checkstyle warns that void helloFunction(T t, X x) { should has indentation level 4 which is my wrapping indentation configuration. I think it looks better if void helloFunction(T t, X x) { is at the same indentation as public static <.

The questions:

  1. Is it expected from Checkstyle?
  2. Is Checkstyle preferences actually better or more compliant to java convention?
  3. Is there any Checkstyle configuration to suit my preference?

Thanks in advance.

1 Answer 1

1

I like your proposed style - it looks cool! However, it is actually quite uncommon, as most people would probably rather write it as something like

public static <T, X> void helloFunction(T t, X x) {
  //some code here...
};

It is of course a matter of personal taste (or your team's tastes), but the most common practice for type variable names is actually to use single capital letters, at most followed by a single digit (see Google Style Guide, the arguably most popular Java coding style guide). Like you mentioned already, this makes the more compact notation possible.

Checkstyle makes a point of following common conventions. There is even a specific bundled configuration for Google Style (report), which enables you to easily use Checkstyle with the Google Style Guide.

I would recommend following an established style guide, as it will make your code more easily readable for other people.

As far as I know (and I probably would), there is no configuration available for your preference. You may, however, write custom checks for it.

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

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.