String concatenation feature or bug?

Found this the usual way (meaning the hard way):

Background: 2024-10-13,06:25:21 beginLP _nextPos 0

		l_pos = '_' + _nextPos;
		_util.logTime("requestLogPos " + _nextPos + ", l_pos " + l_pos);
		
Background: 2024-10-13,06:25:21 requestLogPos 0, l_pos _

		l_pos = "_" + _nextPos;
		_util.logTime("requestLogPos " + _nextPos + ", l_pos " + l_pos);

Background: 2024-10-13,06:25:21 requestLogPos 0, l_pos _0

Characters can work, as in this:

	public function httpURL(php, rest) {
		return _host + php + '/' + G_uID + '_' + System.getTimer() + '_' + _httpRetrys + '/' + rest;
	}

		_util.logTime("requestLogPos l_pos " + l_pos + ", l_url " + l_url);
	
Background: 2024-10-13,06:25:21 requestLogPos l_pos logPos_0, l_url https://my.example.com/g1/lp/ffa0f28f1a9e91d2133a05fc4ff987c817fb2ab4_361254406_0/logPos_0

Multiple characters OK, single characters bad and have to use string as workaround. Normally it wouldn't matter except that strings are objects which add up after a while.

  • Guys! Come'on! This thread won't change anybody's mind who wasn't convinced yet. It certainly won't help anybody else. Can you continue it in private messages? It fills the inboxes of many people and is a bit annoying...

  • Given the number of times you posted here, it’s kind of silly to complain about other people.


    You can turn off notifications for this thread.

  • The behavior of + with Char types is well defined and is unlikely to change.

    You can concatenate two characters into a string with +, and you can apply an offset using a Number.

    System.println('A' + 'B'); // "AB"
    System.println('A' + 1);   // 'B'
    System.println(1 + 'A');   // 'B'
      
    // support for + with Char/Long types was added to the runtime for
    // ConnectIQ 5.0.0, but the compiler still disallows it when detected
    System.println('A' + 1L); // 'B'
    System.println(1L + 'A'); // 'B'

    If you want to talk about inconsistencies with Char, the obvious one here is that you can't subtract an integral type from a Char.

    System.println('A' + 1); // 'B'
    System.println('B' - 1); // does not compile if detected, exception at runtime

    As pointed out above, it is unlikely we'd change these behaviors.