new Class in constructor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    new Class in constructor

    [
    1. Code:
      public class Expression implements IExpression{
      
      public Expression(){} 
      public Expression(new DotExpression()){}}

    why for
    Code:
    public Expression(new DotExpression()){}
    i get illigal start of type


    Thank You
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    You get an error there because you can't put objects into a signature.

    Basically, every time you call a method (and a constructor is a kind of method) you can pass any object you like as long as it fits the signature of that function. But when defining a signature it may only contain modifiers (public, final, static, etc.), a type (if it's no constructor), a name and a list of parameter types and names.

    Comment

    Working...