Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #5100

How to initialise a final static String array

Path csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.java.gui
Subject How to initialise a final static String array
Date Sun, 18 Mar 2012 13:52:41 +0100
Organization Decebal Computing
Lines 45
Message-ID <874ntmxe92.fsf@Compaq.site> (permalink)
NNTP-Posting-Host lYLrXPFpjyZ8237ODaoN+w.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Complaints-To abuse@aioe.org
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)
X-Notice Filtered by postfilter v. 0.8.2
Cancel-Lock sha1:13Aa8XzsAWHMt8gTgpnhTM/ExUQ=
X-Homepage http://www.decebal.nl/
Xref csiph.com comp.lang.java.gui:5100

Show key headers only | View raw


I want to use final for my static variables. I now do for example:
	private static final Connection conn;
	private static final Combo      container;

and
	static {
		Connection tempConn;
		Statement  tempStmt;
		try {
			Class.forName("org.h2.Driver");
			tempConn = DriverManager.getConnection(
					"jdbc:h2:tcp://localhost/~/databases/stock", "sa", "");
			tempStmt = tempConn.createStatement();
		} catch (Exception e) {
			tempConn = null;
			tempStmt = null;
		}
		conn = tempConn;
		stmt = tempStmt;

and
		if (conn == null) {
			throw new Exception("Could not initialise");
		}

The only problem I have is with my array of String.
I now have:
	private static final String[] titles = {
		"Stock",
		"Number",
		"Dare",
		"Container"
	};

Because when I put it in the static block I get an error.
Beside this I can execute a statement like:
		titles[0] = "changed";

Can I get the initialisation in the static part? And in such a way
that the elements can not be changed?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

How to initialise a final static String array Cecil Westerhof <Cecil@decebal.nl> - 2012-03-18 13:52 +0100
  Re: How to initialise a final static String array Cecil Westerhof <Cecil@decebal.nl> - 2012-03-18 13:54 +0100
  Re: How to initialise a final static String array Knute Johnson <nospam@knutejohnson.com> - 2012-03-18 09:50 -0700
  Re: How to initialise a final static String array Lew <noone@lewscanon.com> - 2012-03-18 10:28 -0700
  Re: How to initialise a final static String array Roedy Green <see_website@mindprod.com.invalid> - 2012-03-18 18:12 -0700
    Re: How to initialise a final static String array Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-19 09:34 -0700

csiph-web