title: ANTLR4 Validating user-defined types match
body: <p>I was looking at the Antlr v4 Grammars. Specifically the Java example. </p>
  
  <p><a href="https://github.com/antlr/grammars-v4/blob/master/java/Java.g4" rel="nofollow">https://github.com/antlr/grammars-v4/blob/master/java/Java.g4</a></p>
  
  <p>I noticed that the below input is valid using the provided grammar.</p>
  
  <pre><code>public class HelloWorld { 
      public static void main(String[] args) { 
         Float f = "hello world!";
      }
  }
  </code></pre>
  
  <p>Obviously we all know this is not a valid statement in Java. How in Antlr4 do you invalidate this, and throw an error? I suspect  you do it in the BaseVisitor generated functions but I am struggling to find an example in the Antlr4 book or online.</p>