我们知道我们不必向Java构造函数添加任何返回类型.
class Sample{
.....
Sample(){
........
}
}
Run Code Online (Sandbox Code Playgroud)
在Objective C中,如果我们创建一个构造函数,它会返回一个指向其类的指针.但我认为这不是强制性的.
AClass *anObject = [[AClass alloc] init];//init is the constructor with return type a pointer to AClass
Run Code Online (Sandbox Code Playgroud)
类似地,构造函数是否转换为返回对其自己的类的引用的方法?
像这样:
class Sample{
.....
Sample Sample(){
........
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
编译器是否向构造函数添加了对同一类的引用的返回类型?构造函数发生了什么?有没有参考研究这个?
实际上我希望答案是字节代码级别或JVM级别甚至更低.
我怎样才能将此代码转换为VB.net
public void SetBooks(IEnumerable<Book> books)
{
if (books == null)
throw new ArgumentNullException("books");
new System.Xml.Linq.XDocument(books).Save(_filename);
}
Run Code Online (Sandbox Code Playgroud)
在http://converter.telerik.com/中它说:
Public Sub SetBooks(books As IEnumerable(Of Book))
If books Is Nothing Then
Throw New ArgumentNullException("books")
End If
New System.Xml.Linq.XDocument(books).Save(_filename)
End Sub
Run Code Online (Sandbox Code Playgroud)
但是visual studio说"语法错误".因为"新"
这种情况的关键字是什么,我在Google上搜索但没有结果.