-1

I want to use constant char/string comma (,) in my code.

Where I can find static final variable in standard library? If there is not such a place, can you point me popular external library for that?

EDIT: I don't want to create my own constant, I want to use it from JDK (or external library if it not exists)

ByeBye
  • 6,211
  • 5
  • 28
  • 59

3 Answers3

4

What would be the benefit of depending on an external library for just a constant? If your not using code from that library I would advise to define the constant in your own project.

If you use the comma-constant all over the place in your code try to find a common interface/class and define the constant in that interface/class.

If there is no common interface/class create an enum with a logical name. Do not create a class or interface just for wrapping a constant.

If you need the comma-constant in a single class declare it in that class. (either protected or private).

See also What is the best way to implement constants in Java?

But if you really want to use a third-party library, you might want to look at: https://github.com/google/caja/blob/master/src/com/google/caja/lexer/Punctuation.java

Community
  • 1
  • 1
ipper
  • 564
  • 3
  • 13
  • I know how implement constant and I don't want to know why it is wrong or good to create own constant. I asked WHERE I can find that literal in JDK or external library. – ByeBye Apr 03 '17 at 07:32
  • Well, look at the last paragraph that was added. There it is now. – domsson Apr 03 '17 at 07:42
1

Did you mean this :

public final char CH = ',';
YCF_L
  • 51,266
  • 13
  • 85
  • 129
  • I know how implement constant and I don't want to know why it is wrong or good to create own constant. I asked WHERE I can find that literal in JDK or external library. – ByeBye Apr 03 '17 at 07:37
-1

You can use this:

import sun.tools.java.Constants;

Constants.opNames[Constants.COMMA]
Topera
  • 11,829
  • 14
  • 65
  • 101
easonjim
  • 1
  • 1