是否可以将字符串 10 与数字 10 相乘

Is it possible to multiply the string 10 with number 10

乘法 '10' * 10 给出一些输出值 10101010101010101010

有人能证明这一点吗?

ExpressionParser parser = new SpelExpressionParser();
System.out.println(parser.parseExpression("'10' * 10").getValue());

输出:10101010101010101010

It should throw some exception as in java we cannot multiply string with number.

SpEL 不是 Java 它有一些相似之处,但 不是 Java。它没有 lambda,它对许多事情有不同的语法。

应用于字符串的乘数运算符意味着将字符串连接该次数。

类似于'10' + '10' = '1010''10' * 2 = '1010'

Java文档在 OpMultiply class:

/**
 * Implements the {@code multiply} operator directly here for certain types
 * of supported operands and otherwise delegates to any registered overloader
 * for types not supported here.
 * <p>Supported operand types:
 * <ul>
 * <li>numbers
 * <li>String and int ('abc' * 2 == 'abcabc')
 * </ul>
 */