Java Enums and Fields with same name
<p>I was refactoring some code recently and ended up with a weird compiler error</p>

<pre><code>class CustomerContract{
    public enum BillingTerm{
        MONTHLY,QUARTERLY,YEARLY;
    }

    public String BillingTerm = "";
}

class SalesProposal{
    public String billingCycles(){
        String message = "We have several billing cycles available: \n";
        for(CustomerContract.BillingTerm term : CustomerContract.BillingTerm.values()){
            message += " - " + term.toString() + "\n";
        }
        return message;
    }
}
</code></pre>

<p>I get a compiler error on SalesProposal because it attempts to access the <code>String</code> rather than the enum.</p>

<p>What I'm surprised by is that <code>CustomerContract</code> did not cause a compiler. Can someone explain to me why, and how I might have explicitly referenced the <code>enum</code>?</p>

<p>Please forgive the convention issues my contrived example.</p>