问题描述
我对开发人员的数量感到困惑,因为我看到在类名或方法下方编写花括号的方法和类.他们遵循什么约定?
I'm a bit puzzled by the number of developers I see writing methods and classes with curly braces below the class name or the method. What convention are they following?
Sun 明确声明正确的声明是:
Sun clearly states that the correct declaration would be:
// this declaration follows sun's conventions
class Sample extends Object {
Sample(int i, int j) {
....
}
}
然而,我越来越多地看到它被声明为(甚至在书中):
Yet more and more I see this declared as (even in books):
// this declaration follows a convention I cant identify
class Sample extends Object
{
Sample(int i, int j)
{
....
}
}
我知道一个约定只是一个约定,只要您遵循一个约定,一切都会很好.我只是在寻找后面的声明遵循什么约定的答案?
And I know that a convention is just a convention and, as long as you follow one, all is good. I'm just looking for the answer on what convention does the latter declaration follow?
推荐答案
这是称为ANSI样式的标准样式约定.除了Java以外,它在其他语言中也很常见.
This is a standard style convention called the ANSI style. It's common in other languages besides Java, as well.
这篇关于花括号的约定的名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!