Can we create a Java variable with : operator? -


is ther way declare variable this:

private string xmlns:xsi;  

resulting following error:

syntax error on token ":", , expected 

but, want have ':' in variable name. mandatory.

it mandatory because using jaxb api unmarshal xml file java. in xml have element attribute named xmlns:xsi. now, in pojo have use attribute variable store value. that's why mandatory me have variable name this.

every programming language has own set of rules , conventions kinds of names you're allowed use, , java programming language no different. rules , conventions naming variables can summarized follows:

  • variable names case-sensitive. variable's name can legal identifier — unlimited-length sequence of unicode letters , digits, beginning letter, dollar sign "$", or underscore character "". convention, however, begin variable names letter, not "$" or "". additionally, dollar sign character, convention, never used @ all. may find situations auto-generated names contain dollar sign, variable names should avoid using it. similar convention exists underscore character; while it's technically legal begin variable's name "_", practice discouraged. white space not permitted.
  • subsequent characters may letters, digits, dollar signs, or underscore characters. conventions (and common sense) apply rule well. when choosing name variables, use full words instead of cryptic abbreviations. doing make code easier read , understand. in many cases make code self-documenting; fields named cadence, speed, , gear, example, more intuitive abbreviated versions, such s, c, , g. keep in mind name choose must not keyword or reserved word.
  • if name choose consists of 1 word, spell word in lowercase letters. if consists of more 1 word, capitalize first letter of each subsequent word. names gearratio , currentgear prime examples of convention. if variable stores constant value, such static final int num_gears = 6, convention changes slightly, capitalizing every letter , separating subsequent words underscore character. convention, underscore character never used elsewhere.

via : https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

edit: way if want it.

if need map string values on particular variable. can use hash map

 map<string,string> stringmap = new hashmap<string,string>();  stringmap .put("xmlns:xsi", "variablevalue"); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -