开发者

Why can't I create an variable in an switch block?

开发者 https://www.devze.com 2023-01-03 05:38 出处:网络
Strange: switch(type) { case NSFetchedResultsChangeInsert: int x = 5; // error: \"开发者_如何学JAVAExpected expression before int\"

Strange:

switch(type) {
    case NSFetchedResultsChangeInsert:
        int x = 5; // error: "开发者_如何学JAVAExpected expression before int"

        break;
}

So it isn't possible to create a local variable in an switch-case-block?


Did you try adding curly braces?

switch(type) {
    case NSFetchedResultsChangeInsert:
        {
            int x = 5; // error: "Expected expression before int"

            break; 
        }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消