3

Expected

The ability to use the special character "$" in the naming of a Kotlin or Java variable name. The API for EventRegistry (Example 4) requires the naming of the sub query as "$query". Is there a Kotlin or Java workaround in order to use "$" in a variable name?

Documentation

Example 4 - Request Body

{
    "action": "getArticles",
    "query": {
        "$query": {
            "$and": [
                {
                    "dateStart":"2017-04-22",
                    "dateEnd":"2017-04-22"
                },
                {
                    "$or":[
                        {
                            "conceptUri":{
                                "$or":    ["http://en.wikipedia.org/wiki/Barack_Obama"]
                            }
                        },
                        {
                            "keyword":"Trump"
                        }
                    ]
                },
                {
                    "categoryUri":"dmoz/Business"
                }
            ]
        }
    },
    "articlesPage": 1,
    "articlesCount": 100,
    "articlesSortBy": "socialScore",
    "articlesSortByAsc": false,
    "articlesArticleBodyLen": -1,
    "includeArticleSocialScore": true,
    "resultType": "articles",
    "apiKey": "YOUR_API_KEY"
}

Result

Lint error is thrown when attempting the following:

data class Query(val $query: SubQuery)

AdamHurwitz
  • 9,758
  • 10
  • 72
  • 134
  • Thanks for confirming @ElliottFrisch. I will reach out to the maker of the API EventRegistry to see about a workaround. – AdamHurwitz Dec 30 '18 at 18:59
  • I just double checked. `int $q = 1;` is legal. What's the problem again? Which language and which lint? – Elliott Frisch Dec 30 '18 at 19:00
  • @forpas, awesome! I will give this a try and report back. Do you want to create an answer for your solution? Also, please vote if you think this is useful to others. – AdamHurwitz Dec 30 '18 at 19:49
  • In Java, $ is not a special character. A variable name can include any currency symbol in any position. – Tom Blodget Dec 30 '18 at 23:50
  • Possible duplicate of [Why does this Kotlin method have enclosing backticks?](https://stackoverflow.com/questions/44149474/why-does-this-kotlin-method-have-enclosing-backticks) – LF00 Nov 23 '19 at 08:58

1 Answers1

6

For Kotlin
surround the name with backticks (ascii code 96):
`$query`

forpas
  • 160,666
  • 10
  • 38
  • 76