47

This question is currently closed as "too broad": What does the '{' symbol (curly-brace) indicate in Java?

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.

Note that it currently does have a fairly well-received answer consisting of only a few paragraphs, which would seem to dispute the problem asserted in the close reason, but perhaps I'm overlooking something here.

I'm bringing this up because the question has been repeatedly closed and reopened, deleted and undeleted, over the past few days. Thus far, none of the people who have closed or reopened it have raised a discussion on the matter here (there is a procedural question related to it, but little discussion of the merit of the question itself can be found there).

In hopes of resolving this before Christmas, I've made some significant edits to clarify the question; therefore I ask anyone who feels that it remains problematic please post an answer here explaining your rationale.

48
  • 8
    Guess, you shall. Everyone wants to defend their right to remain silent about their votes these days.
    – BoltClock Mod
    Commented Dec 23, 2016 at 18:01
  • 2
    I posted comment to that question with link to Java docs before that "well received answer" was posted. Actually, minutes show the same time, still. And first version of that answer was actually half arsed, so... My personal feeling is that the whole thing should be nuked, but I am not a newbie so...
    – Dalija Prasnikar Mod
    Commented Dec 23, 2016 at 18:44
  • 3
    Any answers site with a cavalier attitude to quality is eventually going to explain how babby is formed. Commented Dec 23, 2016 at 18:44
  • 7
    And BTW that answer is actually wrong... single unified meaning of curly brace is start of a block... there are no different meanings depending on the context. Block is one thing, what block represents under different contexts is another.
    – Dalija Prasnikar Mod
    Commented Dec 23, 2016 at 18:50
  • 2
    To be transparent: the link to that question was posted in SOCVR and moved out of our transcript once it was closed. I pinged a couple of members that have been moderating that question here
    – rene
    Commented Dec 23, 2016 at 18:50
  • 1
    @NathanOliver Yes. From Java documentation: A block is a group of zero or more statements between balanced braces and can be used anywhere a single statement is allowed.
    – Dalija Prasnikar Mod
    Commented Dec 23, 2016 at 18:54
  • 4
    FWIW, "am I overlooking something, or does this question present a quixotic goal?" sounds like a way more broad question than what it was before.
    – TylerH
    Commented Dec 23, 2016 at 19:03
  • 1
    Mind posting an answer here, @DalijaPrasnikar? FWIW, there seems to be some rather wide-spread confusion on that point, so if the answer is as trivial as you suggest then perhaps it would be beneficial to get the word out...
    – Shog9
    Commented Dec 23, 2016 at 19:23
  • 1
    My goal when editing was primarily to forestall "this is one thing a brace is used for" answers, @TylerH, since that was actually a problem at one point. Quite honestly, I'd be more'n happy to see it closed as a duplicate of a Docs topic... If that was possible... And a suitable topic existed. But I can't even find a suitable Q&A topic as a dup-target, so it'd be rather nice if someone with a deeper knowledge of Java would put this to rest (in a manner that isn't "this is trivial everyone knows the answer also all the answers are wrong").
    – Shog9
    Commented Dec 23, 2016 at 19:27
  • 4
    That's fine, @DalijaPrasnikar; it's sat for 4 days already, ain't gonna hurt it to sit a bit longer. I might just lock it for the weekend anyway, since I'm guessing a lot of folks have more pressing concerns.
    – Shog9
    Commented Dec 23, 2016 at 20:24
  • 2
    in case if meaning can be expressed and there are multiple ways to express it, how are readers supposed to decide which is better? Does this "description golf" have some rules or it is expected to be a pure popularity contest
    – gnat
    Commented Dec 23, 2016 at 21:09
  • 11
    If anything, that question can be closed as duplicate of stackoverflow.com/questions/4484884/java-just-curly-braces. It has the actual real and only correct answer. And it merits deletion (at least to me) because it's the very first result for a Google search "java what does curly brace mean", along with a full page of related and useful content.
    – Tunaki
    Commented Dec 23, 2016 at 21:24
  • 3
    @alfasin I don't think it should be permitted. Otherwise it's just a test of which side is stubbornest and in the meantime the question gets caught in the cross fire. Commented Dec 24, 2016 at 18:03
  • 2
    @Glenn Well, parentheses are definitely not brackets or braces and can't be argued to be such. They're so special that they have their own unique name.
    – TylerH
    Commented Dec 25, 2016 at 5:55
  • 3
    I would guess that a lot of the downvotes, close votes, and delete votes on that question are the voter's way of saying "the meaning(s) of curly braces can surely be found in your textbook; please read it." Commented Dec 25, 2016 at 8:49

6 Answers 6

36

First of all, I disagree that the question is too broad. But one would first have to clarify exactly what the question is. The first revision asks for the meaning of { -- which raises the question: In which context? What does the asker really wants to know, and what kind of answer are they looking for?

Curly-braces, in and of themselves, are a lot of different "meanings", depending on what "meaning" represents:

I could go on like this, there are hundreds of possibilities here, and I suspect each and every one of them already has a (or probably, multiple) questions about it. Is the OP asking for one of those meanings? I suspect this is why the question was closed as too-broad: if one would have to get into all of the possible usage of the curly-brace, explaining how it pertains to each and every combination, it would really be too broad.

If we replay the history here, what happened is that an unclear question (see above), obviously not researched (searching for Google "java what does curly brace mean site:stackoverflow.com" yields all of the questions I linked above, no exceptions, and removing the "site:stackoverflow.com" returns other blogs or articles talking about each usage as well, in the pages of pages of results) was answered with "The question is not so great". The answer followed to talk about the possible meanings I quoted above, best guess they could make. At that point in time, the thing deserved to die because of that.

Somehow, the question had a lot of attraction, no idea why, as those type of unclear questions with guesses as answers are a daily problem (or even a hourly problem) and constant source of pain in the Java tag. In all the confusion and excitement, edits focused on trying to have a definite answer by rewording to "Is there a universal meaning?". Funnily enough, no, there isn't. The Java Language Specification uses the curly-brace as the beginning of a block. A block actually encompasses practically all of the structures and contexts shown above in a single concept. Except for the case of the initialization of arrays, that isn't a block and doesn't fall under this universal meaning.

I won't count the amount of time that has passed into trying to salvage the thing, on Meta, on the various votings and queues, but it's impressively too great. In any case, the edited question, (that invalidated the answers) can be answered with "No". I don't believe this is helpful and I don't believe people reading it will learn things from it, for the sole reasons that the next question is going to be "What is the meaning of a block?", which is too broad to answer. If we remove arrays of the equation, it is a duplicate of this question.

18
  • 8
    "I disagree that the question is too broad" then "crap load of links with different meanings", how is that not too broad (lack of scope and/or context)?
    – Braiam
    Commented Dec 23, 2016 at 22:52
  • 4
    @Braiam Because to answer a question, you first need to comprehend it. If we consider the initial revision, I do not comprehend it. I can guess, but that isn't helpful.
    – Tunaki
    Commented Dec 23, 2016 at 22:53
  • 1
    By too broad I meant "Even if you explain what you're trying to achieve (e.g. "What { means?") if you don't explain where you're having trouble accomplishing that, answers would need to cover too many different things and end up being too long." The OP failed to provide a bit of context that could help to narrow it down.
    – Braiam
    Commented Dec 23, 2016 at 22:57
  • 3
    At least, lots of users earned hats from that Java question...
    – Tunaki
    Commented Dec 23, 2016 at 22:58
  • Ha, no doubt about it.
    – Braiam
    Commented Dec 23, 2016 at 22:58
  • @Braiam Bah sure you can see it that way, I guess it depends if you see it as "Okay, you didn't provide context but you probably want this, so I'll talk about all the usage" (too broad - guess answer, what we ended up with), or "Okay, you didn't provide context, please clarify what it is you're really asking".
    – Tunaki
    Commented Dec 23, 2016 at 23:00
  • 2
    "big drama will lead to absolutely nothing" yeah, I would wait a couple of weeks, when everyone is looking at 2016S, we delete it again, like that hadoop question.
    – Braiam
    Commented Dec 23, 2016 at 23:10
  • @Braiam and then I'll come again and undelete it. If that's how you play I can do it too. Happy holidays!
    – Nir Alfasi
    Commented Dec 24, 2016 at 2:21
  • @Tunaki as I wrote on the other post I opened on meta I believe that not only this question is not too broad, but also an important and valuable one:
    – Nir Alfasi
    Commented Dec 24, 2016 at 2:28
  • 1. the answer demonstrates that it's not too broad by providing a good answer that covers all the options in a few concise paragraphs. 2. I think that it's valuable since a common meaning to all the options is "a start of new scope". The meaning of scope is something that many young developers struggle with and a good and clear answer could be beneficial for many people.
    – Nir Alfasi
    Commented Dec 24, 2016 at 2:28
  • 2
    @alfasin I hope you try I really do
    – Braiam
    Commented Dec 24, 2016 at 2:32
  • 1
    @alfasin You're barking the wrong tree, what I said was too broad would be to explain every aspects and usage of curly-braces, along with why you would use it, JLS quote, what it does, what it implies, etc. For example, the answer doesn't cover anonymous inner class (and the subtelty of adding {}), nor instance initializer or static initializer and how they play with class initialization, when they are invoked, etc. There are more examples.
    – Tunaki
    Commented Dec 24, 2016 at 9:55
  • 4
    @alfasin And your comment is why I consider the edited question not useful: answer is going to throw up a general word; that you cannot explain because you're back at square one anyway. In end end, people wondering about { will wonder about something else, and nobody has gained anything out of it. But don't worry.... the thing isn't going to go. Now that the big mess was created, everything will stay untouched.
    – Tunaki
    Commented Dec 24, 2016 at 9:57
  • 3
    @alfasin Yes, the question should be left alone now. The edit fixed its unclearness, with the effect of invalidating the answer provided at that time. There is now an answer, which is "No". I just don't think it's a useful answer that'll help anyone in the future, but at least it's answerable and doesn't deserve deletion. What did deserve deletion was the question in the state it was before (and that is when I voted to delete it). Let's all just realize that, while this discussion lasted several days, hundreds of questions exactly like that one were posted, some of those rightfully deleted.
    – Tunaki
    Commented Dec 24, 2016 at 18:10
  • 1
    This is also probably the best answer to the question on SO, should we migrate it? Commented Dec 24, 2016 at 18:56
12

I think what we've seen happening with questions like this (excessive downvoting, close-voting and delete-voting) is a knee-jerk reaction. The question strikes a nerve because it's so ... useless. Yes, that sounds harsh, but read on.

It's like every other "Why was this API/language designed like this?" question to me, and I don't like such questions on Stack Overflow. The upvotes, positive comments and reopen- or undelete-votes on such questions and their answers always seem to be coming from people who know the answer to it and would want to post it, or who know the posted answer is correct and would want to keep it visible on the site. That does not make it a good question though.

Yes, it is a question that is related to programming. Yes, there are ways to write an answer for it that is a couple of paragraphs long and explains the issue at hand.

But nobody who is at the moment working on programming something is going to search for that question, other than out of sheer curiosity, and the answer isn't going to help them any further.

So perhaps it's time for you, the moderators, and/or us, the community to for once and for all answer the question:

Is a language design questions a "practical, answerable problem that is unique to software development"?

I mean, the answer to almost every question in the language-design tag is "because". I'm not denying most of these are fun to read, and their answers are informative, but they're not going to help you any further when you're stuck with a programming problem.

And I was living under the assumption that the latter was a criterion for a question for being on-topic. I'd love to be proven wrong though.

7
  • 6
    I agree with the first paragraph's diagnosis of the fundamental problem here, but I strongly disagree (and always have) with language-design questions generally being off-topic, impractical, not useful, or otherwise bad. Yes, there are only a very limited number of people competent enough to answer them, but that is a non-issue for SO and in many ways, a hallmark of an interesting, non-trivial question. As for this "practical" aspect, I think people are overthinking it. It's meant to discourage navelgazing questions, not questions about why a practical language design decision was made!
    – Cody Gray Mod
    Commented Dec 24, 2016 at 9:57
  • @CodyGray: Can you differentiate between navelgazing as you put it and asking why design decisions were made? Bear in mind, not all of us are privy to those design meetings.
    – Makoto
    Commented Dec 24, 2016 at 10:06
  • 5
    Asking why a language is designed a certain way is very practical to users of that language. It is very difficult to distinguish between "how does this work?" and "how was this designed [to work]?". I just don't get the impulse to ban these types of questions and turn Stack Overflow into a code-debugging service. It's already gone too far in that direction to satisfy me. Being privy or not privy to the design meeting is irrelevant. Many users are not knowledgeable about x86 assembly language, either, but that doesn't make questions about it off-topic.
    – Cody Gray Mod
    Commented Dec 24, 2016 at 10:09
  • @Cody stop proving me wrong. :P I can see where you're coming from, and I'm afraid I have to agree.
    – CodeCaster
    Commented Dec 24, 2016 at 10:15
  • @CodyGray serious question: do you believe "what { means in java?" is a "non-trivial question" and why? I know next to nothing about Java, but if I had the same query, I could have found the answer just as easily.
    – Braiam
    Commented Dec 24, 2016 at 12:28
  • 1
    @Braiam No, I'm not trying to defend this particular question. It doesn't even seem like a language-design question to me. I think it falls more under the "general reference" category, which probably makes it "too broad". I don't know anything about Java either, but I'm imagining it asked about C++. The only thing that might save it in C++ would be the [language-lawyer] tag, and someone posting a good canonical reference quoting and interpreting the language specification.
    – Cody Gray Mod
    Commented Dec 24, 2016 at 12:37
  • @CodyGray I was just trying to extract a opinion on the matter, your view aligns with my own anyways. But thanks.
    – Braiam
    Commented Dec 24, 2016 at 14:42
11

This feels uncomfortable since this question nicely fits in the context of a bikeshed-style question.

First of all, let's give credit where credit is due; the answer is well done, complete and succinctly answers the question as posed. There is a narrow (and we'll revisit this soon) definition as to what this particular piece of syntax implies in Java, and it's well covered in the answer.

However, this leaves a weird taste in my mouth because it's very simple to find this kind of information out. Perhaps not with the exact same phrasing - you're likely not going to find any major posts exclusively discussing the left-brace - but it's not too terribly difficult to find out.

Thus, we arrive back at the bikeshed nature of this question. It's almost too simple to provide an answer to it. But is it really a valuable answer? Why not discuss what block statements mean or what the static initializer {{ }} does? None of that is really asked for, but it is provided, which means that the answerer had to cover more bases.

It's simple, but it just feels...wrong.

I suppose this is more of a question culture issue more than anything else. Do we want to permit these kinds of questions - questions which have likely good intention but are just a bit unfocused, and incredibly easy to answer - to linger around here? Personally, I don't; the question is discussing the left brace, but not really its use in any specific context.

The edit you did was good Shog, but it didn't bring any more focus to it. It's not too broad in the context of it being, "how do I do X" or "how do I use Y", but it is too broad because there's a lot of noise to weed through to get to the signal. We don't really know what context they're using the left-brace in.

13
  • 2
    If the question is answerable, on-topic, and not a duplicate, I see no reason for it to be closed or deleted. If the question is answerable, on-topic, and reasonably covered by another Q&A, then it should be closed as a duplicate. Do we really need to get into "that question is too basic" or "that information is too easily found elsewhere on the internet" type arguments? That seems like it is opening up every question that is basic or could be easily answered by reading the relevant documentation to be closed or deleted. That isn't a direction I feel is good for the site.
    – user4639281
    Commented Dec 24, 2016 at 1:51
  • @TinyGiant: The main thing is to determine if it's on-topic, first. Yes, the "too easy" portion of this debate does somewhat sway my opinion on this, but in all honesty, why would an unbound question about { be objectively on-topic? It could be a lot of things, and it depends on the situation that it's being used in. I don't deny that the current answer covers most of these angles, but we as a community have balked at similar questions before.
    – Makoto
    Commented Dec 24, 2016 at 1:56
  • @TinyGiant: To that end, the discussion about questions that are "too basic" has been lingering around in the background for quite some time. It's not an easy problem to solve, and it's not a pretty problem to discuss, so many people who have a strong opinion on it one way or another tend not to discuss it that frequently.
    – Makoto
    Commented Dec 24, 2016 at 1:57
  • 1
    Your answer seems most focused on how basic the question is, that is what I argued against. Adherence to the guidelines and relevence to the topic of this site are, in my opinion, the only acceptable metrics to use when evaluating closure of a question. Usefulness has its own voting system.
    – user4639281
    Commented Dec 24, 2016 at 5:37
  • 2
    @TinyGiant: Usefulness is often very strong and pivotal to evaluate when discussing whether or not a question should be undeleted and reopened and stay that way. It's almost like the coin toss in a tie breaker scenario.
    – Makoto
    Commented Dec 24, 2016 at 10:00
  • Some users may be less willing to vote to close useful but off-topic questions, just like some users may be less willing to reopen on-topic but useless questions. You shouldn't vote to close a question solely because it is not useful, just like you shouldn't vote to reopen a question solely because it is useful.
    – user4639281
    Commented Dec 24, 2016 at 19:09
  • @TinyGiant: I disagree. Given the question's checkered history, it's time to start looking at all possible avenues to justify it staying open. If we can't find a valid reason for it to stay open at all, then it likely should stay closed.
    – Makoto
    Commented Dec 24, 2016 at 19:10
  • Closure needs to be justified, staying open does not need to be justified. If you don't want to vote to reopen a question because you don't think it is useful, that's fine. My objection is to the implication that it should be closed solely because you think it is not useful.
    – user4639281
    Commented Dec 24, 2016 at 19:10
  • Notice that the question is currently open, and has been since yesterday.
    – user4639281
    Commented Dec 24, 2016 at 19:13
  • 1
    @TinyGiant: I'm confused; did you not read in my answer where I stated that the question itself was too broad? The usefuless addendum comes into effect with our side conversation, and is one of the additional angles to consider when deciding if this question should be closed. The only real reason I haven't taken any action against the question is because the community should be discussing it, as we are now, to form some kind of consensus on what to do with it.
    – Makoto
    Commented Dec 24, 2016 at 19:16
  • I'm not arguing that it isn't off-topic, I'm arguing that usefulness should have nothing to do with the argument for closure. If you want to use that as a metric to personally decide whether you want to cast a close vote or not, that's fine; but it should have nothing to do with the discussion of whether or not it is off-topic. As I said, the majority of your answer is about how you think it is not useful, which is what I have a problem with. If you want to make a case for it being off-topic, that would be much more constructive.
    – user4639281
    Commented Dec 24, 2016 at 19:22
  • Currently only the last paragraph of your answer really talks about it being off-topic. The rest is entirely about how you think the question and its answer are not useful.
    – user4639281
    Commented Dec 24, 2016 at 19:23
  • I think question along with answers started to grow from trivial to complex to partially opinion based. When you start digging deeper there are different interpretations. Or should I say it is matter of opinion whether definition is trivial or not... getting too convoluted for me...
    – Dalija Prasnikar Mod
    Commented Dec 25, 2016 at 11:49
7

Chain of events

I bumped into that question immediately after it was asked. It took me about 30 seconds to Google for an appropriate link, and I posted it as a comment together with a short answer to the question. While I was typing my comment another comment arrived stating same thing, but without the link, so I posted my comment anyway.

While I was deciding what close vote reason I should use, an answer arrived. It was a bad answer: I wanted to downvote and post a comment but I didn't feel like getting involved with a FGITW 200K user. So I moved on, forgetting to cast my close vote. Anyway, I thought this kind of question would get moderated soon because it is either a trivial question or an "Ask your teacher" kind of question.

Question - first version

My teacher asked a question that I don't quite understand, he asked: what is the meaning of the following symbol in java '{'?

I'm confused as to what EXACTLY is the correct way to answer this question.. As it could be the start of a method, or if statement, for loop..etc.. I looked online and was unable to come up with the answer I was looking for.

Thanks,

The answer to that is rather trivial: "it is the beginning of a block", then "ask your teacher, read a Java book".

But when it comes to symbols sometimes it is hard to search and find an appropriate answer if you don't already know the answer. I felt that the OP could use a hint so I posted the following comment:

It is start of a block https://docs.oracle.com/javase/tutorial/java/nutsandbolts/expressions.html

However, the link does not cover array initialization because that is not a statement block but an expression block. Mea culpa... But that is why I commented instead of posting an answer, because I thought there was no need to answer.

Also from a programming practice POV, a detailed answer to the question does not matter. There is no different meaning or possibility to misuse or misunderstand braces. If you manage to put one in the wrong place, have too few or too many of them, such a coding question could be closed as a typo.

Answer - first version

This seems like a not-so-great question - it can mean all sorts of different things by context.

In the context of a statement, the { symbol is used to denote the start of a block statement. This accounts for all the uses of { with if statements, while loops, for loops, do ... while loops, switch statements, etc., which technically only apply to a single statement but are often used with block statements.

In the context of a method or class, the { symbol is used to denote the beginning of the body of a class or a method. It can also be used inside a class to declare an initializer or static initializer block. This is entirely separate from the syntax used in block statements.

Actually, there is nothing wrong with the question itself, but it was IMO asked in the wrong place. Also, if one thinks it is such a bad question, why answer it with an equally not-so-great answer?

IMO the answer is wrong. Braces do not carry any context themselves; it is the code around them that gives the context. And actually according to the Java language specification braces are separators.

From my POV, the question should either be deleted or be left open so other answers can be added.


Since the question is now opened, and it has not-so-great answer, I reluctantly decided to post my own. If the whole thing gets deleted that is fine with me, but I would rather not leave the question lingering on the site with half an answer.


Update:

In the meantime it turned out that I don't have exact proof backing up my stance. While I haven't changed my position much, another more coherent answer by Mark Amery appeared and since differences between my POV and that answer lie more in opinion based area I decided to remove my answer.

2
  • "There is no different meaning or possibility to misuse or misunderstand braces" - not true. One of basic meanings of a code block is a nested scope. This is not so trivial to beginners that start programming. And it looks like it's not trivial even to a user with your rep since you're writing: "Braces do not carry any context themselves" which is again, not true.
    – Nir Alfasi
    Commented Dec 24, 2016 at 17:49
  • 1
    @alfasin Well, you might be right when it comes to nested scope, but even then it is not the braces themselves that have context, but the code around them. It is where you put the braces that matters, they are just markers. And as far as beginners are concerned, it is hard for me to imagine them using braces for limiting scope without knowing it, and if they do and their code does not work as expected it would again fall more into typo kind of question, even though there is additional explanation behind it worth stating.
    – Dalija Prasnikar Mod
    Commented Dec 25, 2016 at 11:42
5

In comments on this question, I guessed that the downvotes were due to the topic being easy to find in a textbook, and @alfasin challenged me to find an example:

I would guess that a lot of the downvotes, close votes, and delete votes on that question are the voter's way of saying "the meaning(s) of curly braces can surely be found in your textbook; please read it." – TigerhawkT3

@TigerhawkT3 you'd be surprised how not trivial it is to find such thing in a text-book. I challenge you to search for examples :) – alfasin

I took some Java classes a few years ago, and I got the ebook version of the textbook (Introduction to Object-Oriented Programming With Java, 5TH Edition, C. Thomas Wu). Guess what?

cover curly brace brace answer

<compound statement> is a sequence of Java statements surrounded by braces

The braces are necessary to delineate the statements inside the block. Without the braces, the compiler will not be able to tell whether a statement is part of the block or part of the statement that follows

So, to answer this Meta question, it doesn't really look like the question is too broad. Curly braces group multiple statements into a block. However, as you can see, this can be easily found in a textbook, demonstrating a lack of research, so I'd say that "off topic > other > SO is not a tutorial service" would be an appropriate close reason.

6
  • Well first of all kudus for the findings. Of course that when you already know a book that covers this topic it's "a bit" easier to find :) I'm programming in Java for over 15 years, read lots of technical book, a few Java books and I had hard time to find a good book that covers this topic thoroughly. BTW, the book you introduced above does a poor job of showing only one use (grouping statements in if-else blocks). As we already know there are other uses some of which have deeper Java/OO concepts such as context (closure) and etc.
    – Nir Alfasi
    Commented Jan 2, 2017 at 4:00
  • 2
    @alfasin - Oh, I never read the book; I learned with lectures and lab assignments. I just looked for "curly brace" in the index (a reasonable expectation for independent research) and went where it pointed me. I would be surprised if the OP who asked about braces had a Java textbook that didn't explain braces, with an accompanying reference in its index. If they read that and needed clarification, or more specific info, that might be a better question to ask here. Commented Jan 2, 2017 at 4:08
  • BTW, this could even more trivial if you used an ebook: ctrl+f, type "curly braces".
    – Braiam
    Commented Jan 2, 2017 at 23:31
  • @Braiam - I actually did that initially, but it might be considered too advanced for basic research. Besides, the index referred me to the place where braces were actually explained instead of every place they were merely mentioned, so it worked out well. :) Commented Jan 3, 2017 at 0:58
  • Now... I wonder if this is somehow a breach of some license by posting the content here as CC-BY-SA
    – user4639281
    Commented Jan 4, 2017 at 23:05
  • @TinyGiant - Nope. Fair use. Commented Jan 4, 2017 at 23:53
-4

Can the meaning of the curly brace in Java be expressed in a few paragraphs?

No need of paragraphs, a bit more than a single line is enough:

A block is a group of zero or more statements between balanced braces and can be used anywhere a single statement is allowed. source

Now, the real question is: do this question makes that information easier to find? A query on java curly braces returns the following:

  • http://www.xyzws.com/javafaq/what-are-braces-in-java-for/105

    Braces, also known as curly braces, use { and } to delimit compound statements.

  • What do curly braces in Java mean by themselves? (this is the one some claim that it should be closed as duplicated of)

    The only purpose of the extra braces is to provide scope-limit. The List copy will only exist within those braces, and will have no scope outside of them.

  • Why is this Java code in curly braces ({}) outside of a method?

    Normally, you would put code to initialize an instance variable in a constructor. There are two alternatives to using a constructor to initialize instance variables: initializer blocks and final methods. Initializer blocks for instance variables look just like static initializer blocks, but without the static keyword

  • https://www.cis.upenn.edu/~matuszek/General/JavaSyntax/parentheses.html

    Braces ("curly braces")
    Braces are used to group statements and declarations.
    The contents of a class or interface are enclosed in braces.
    Method bodies and constructor bodies are enclosed in braces.
    Braces are used to group the statements in an if statement, a loop, or other control structures.

  • https://beginwithjava.blogspot.com/2008/07/parens-and-brackets-and-braces-oh-my.html

    We discussed curly braces in Code Blocks, and mentioned briefly that they are a form of divider in Java in Those Pesky Semicolons. Curly braces mark the start and end of a code block.

    Hold the phone! There's another use of curly braces. They can also be used to enclose a list that is used as an array initializer. For example: int nums[] = {1, 2, 3}; (I'm not sure of the last this statement, it looks like JS)

Most of these results already tell us "what curly braces means in the context we are trying to explain" (since I just quoted what those results said about {} and not about their context) if that was the question. I don't see why we would need an extra one for that regard? I see that SO already have enough content that we could answer the query.

10
  • 7
    "do this question makes that information easier to find [sic]" ... most of the questions on this site could be answered by reading the relevant documentation (not to be confused with Documentation). Does that mean that all of those questions should be deleted?
    – user4639281
    Commented Dec 24, 2016 at 1:35
  • @TinyGiant why they shouldn't?
    – Braiam
    Commented Dec 24, 2016 at 2:07
  • Mainly because that would mean deletion of most of the content on the site, and alienating a large portion of the user base. Among other reasons.
    – user4639281
    Commented Dec 24, 2016 at 5:39
  • 3
    @Braiam: The whole point of SO is to create a knowledgebase, where the primary means of indexing it is by a problem to be solved, posed as a question. Some problems are simple enough that a documentation excerpt could resolve them. They are still problems which actual users face and therefore which ought to be part of our knowledgebase. Outside of typos and the like, we don't have a policy of ignoring problems because someone considers them trivial. Commented Dec 24, 2016 at 5:40
  • 1
    @NicolBolas yes, create, the most adeptly used word here, not regurgitate, nor duplicate, nor mirror, but create high quality content or at least unbury the good content. This Q&A doesn't do the later as Tunaki and I demonstrated, and experts say that the answer is also wrong. I fail to see what would be positive about keeping this question around.
    – Braiam
    Commented Dec 24, 2016 at 11:54
  • @TinyGiant how so? We have repeatedly deleted useless content available elsewhere. This content is available elsewhere in a better form (SO for example, on another set of questions). And experts on the matter says that it's flatly wrong.
    – Braiam
    Commented Dec 24, 2016 at 12:26
  • Some think it is wrong, some don't...
    – Dalija Prasnikar Mod
    Commented Dec 25, 2016 at 11:51
  • 1
    @DalijaPrasnikar well, you are saying elsewhere that the meaning of the { seems to be a matter of opinion, so, to be fair, in a site that strive for technical accuracy, opinions are always wrong and technically correct is the only (not the best) kind of correct.
    – Braiam
    Commented Dec 25, 2016 at 15:38
  • 1
    @Braiam Of course, technically correct is imperative. Sometimes technically correct is hard to determine. For instance, the only real definition of curly braces in Java Language Specifications is they are separators. In all other places braces are just part of the "grouping syntax". I would say that braces have no deeper meaning, and if deeper meaning would matter JLS would explicitly state that. IMO that renders this whole Q/A rather useless because it has no practical value.
    – Dalija Prasnikar Mod
    Commented Dec 25, 2016 at 16:00
  • 1
    @DalijaPrasnikar which is my point. Whatever practical that could be extracted from the usage of {, already exist on SO and elsewhere, and makes the Q woefully redundant and potentially misleading, the later of those that I consider unacceptable on a technical site.
    – Braiam
    Commented Dec 25, 2016 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .