Classes

Can you have a class within a void?

Answers

  • Answer ✓

    Keyword void declares that a method doesn't return anything.
    Methods live inside classes.

  • Answer ✓
    1. Not about Using Processing, so I moved the topic.
    2. The answer is yes, if I understood correctly it. It is a bit vague, as GoToLoop understood it differently...
  • Answer ✓
    void setup()
    {
      size(800, 800);
    
      foo();
    }
    
    void foo()
    {
      class Gah
      {
        int a, b;
    
        public String toString() { return a + " " + b; }
      }
    
      Gah g = new Gah();
      g.a = 1;
      g.a = 2;
    
      println(g); 
    }
    

    I never had to use this capability in my code... Perhaps to make an anonymous class less anonymous but still limiting its scope?

  • Answer ✓

    Arf! Forgot about anonymous class! Generally, I like to create a field to store it! :-\"

Sign In or Register to comment.