On Saturday, 19 May 2018 at 07:57:39 UTC, KingJoffrey wrote:
On Saturday, 19 May 2018 at 04:01:18 UTC, KingJoffrey wrote:
[...]
----------------
module test;

@safeinterface class Dog
{
    private string noiseType = "woof";

    public string makeNoise()
    {
        return this.noiseType;
    }
}

void main()
{
    import std.stdio;

    auto dog = new Dog;
dog.noiseType = "meow"; // no way jose - requires use of the safe interface!
    writeln(dog.makeNoise()); // phew! cause dogs can only bark.
}
-------------------

I ported your example to Java. Surprisingly, it compiled and executed just fine:

--- test.java
class test
{
        static class Dog
        {
                private String noiseType = "woof";

                public String makeNoise()
                {
                        return this.noiseType;
                }
        }

        public static void main(String[] args)
        {
                Dog dog = new Dog();
dog.noiseType = "meow"; // no way jose - requires use of the safe interface!
                System.out.println(dog.makeNoise()); // phew! cause dogs meow.
        }
}
---

Reply via email to