0

I am writing a code for creating an Excel sheet programmatically. But, whenever I am exporting it as a jar, the created jar replaces all the constants used with their values.

Source Code:

XSSFRow row0 = mySheet.createRow(rowStartPos);
XSSFCellStyle style = myWorkbook.createCellStyle();
style.setBorderTop(CellStyle.BORDER_DOUBLE);
style.setBorderBottom(CellStyle.BORDER_THIN);
XSSFFont font = myWorkbook.createFont();
font.setFontHeightInPoints((short) 10);
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setFont(font);  

Jar Code:

XSSFRow row0 = my_sheet.createRow(rowStartPos);
XSSFCellStyle style = my_workbook.createCellStyle();
style.setBorderTop((short)6);
style.setBorderBottom((short)1);
XSSFFont font = my_workbook.createFont();
font.setFontHeightInPoints((short)10);
font.setBoldweight((short)700);
style.setFont((Font)font);

which might be the default behavior, but does not help my cause. What should I do to keep those Constants as it is?

  • 1
    Does this answer your question? [Java static final values replaced in code when compiling?](https://stackoverflow.com/questions/5173372/java-static-final-values-replaced-in-code-when-compiling) – PatrickChen May 21 '20 at 06:47
  • Actually, the mentioned question has constants in the developing class only, but in my case, the constants are defined in other classes which are deployed as plugins for use – Vishal Kulkarni May 21 '20 at 07:17
  • You are using a `jar` which is all compiled class files right? Should be the same thing – PatrickChen May 21 '20 at 07:53
  • It doesn't matter whether the constant is defined in your own classes or in a library, on compile, the Java compiler will inline usage of constants. Why is this a problem for you? – Mark Rotteveel May 21 '20 at 07:53
  • The key point is you want to know when JVM replace the constant and how, all in compile time – PatrickChen May 21 '20 at 07:54
  • I don't want it to replace the constants, is there any way I can do that? – Vishal Kulkarni May 21 '20 at 08:22

0 Answers0