オブジェクトを内部的にハッシュテーブル(JavaScriptなど)として処理する言語を学びたいと思いますが、オブジェクトを強力な型でラップして、設計時にコード補完/インテリセンスの利点を提供することができます。これが私がこの夢の言語が機能することを望む方法です:
public class Lion
{
public void Roar() { Console.WriteLine("Aaarrgghh");}
}
public static Main(string[] args)
{
object myCat = new object(); // just plain object, no type!
// adding a Roar() method to the myCat instance
myCat.Roar += delegate() {Console.WriteLine("Miauew");}
// At this point myCat should qualify to be a Lion.
// So we should be able to successfully duck-type-cast
// her to a lion
Lion myLion = myCat as Lion;
// now the myLion reference is strongly typed,
// so I expect the Intellisense window pop up
// and offer me the Roar() method when I hit the dot after "myLion"
myLion.Roar();
}
このプログラムがエラーなしでコンパイルされ、例外なく実行 され、コンソールに「Miauew」と出力されることを望みます。これを行うことができる言語はありますか?多分C#4.0?