Re: [Vala] access static method



Thanks a lot, the only different i see is that my method inside the class is NOT static

Is this still working if you change from

public static void static_method () {
            print ("This is the class method\n");
        }

to

public void static_method () {
            print ("This is the class method\n");
        }


Thank you very much for help!!!


Am 26.03.19 um 17:21 schrieb Miguel Miranda:
namespace MyNamespace {

    public static void static_method () {
        print ("This is the namespace static method\n");
    }

    public class MyClass : Object {

        public static void static_method () {
            print ("This is the class method\n");
        }

        public void some_method () {
            static_method ();
            MyNamespace.static_method ();
            MyNamespace.MyClass.static_method ();
        }


        public static void main () {
            var a = new MyClass ();

            a.some_method ();
        }
    }
}


After running:

This is the class method
This is the namespace static method
This is the class method

It seems to work fine, it even follows the implicit hierarchy of invoking the class method when no namespace or class is mentioned.



On Tue, Mar 26, 2019 at 4:07 PM Wolfgang Mauer <wolfgang mauer kabelmail de <mailto:wolfgang mauer kabelmail de>> wrote:

    Thanks for your answer...
    That's what i thought
    but if i try to use "valaDevelop.get_text" inside method mymethod
    in class abc
    the compiler say:
    /home/wolfgang/Projekte/vDevelop/valaDevelop/completion_provider.vala:59.80-59.99:
    error: The name `get_text' does not exist in the context of
    `valaDevelop.valaDevelop'
                _symbol_match =
    _symbol_finder.find_symbol_by_name(word.strip(), _fullpath,
    valaDevelop.get_text((SourceBuffer)currentIter.get_buffer()),
    currentIter.get_line()+1, currentIter.get_line_offset());
    ^^^^^^^^^^^^^^^^^^^^
    Can that be a Bug?
    :-(


    Am 26.03.19 um 16:56 schrieb Miguel Miranda:
    Namespace static method:

    Namespace.staticmethodname ()

    Class method:

    Namespace.class.staticmethodname ()

    On Tue, Mar 26, 2019, 15:25 Wolfgang Mauer
    <wolfgang mauer kabelmail de
    <mailto:wolfgang mauer kabelmail de>> wrote:

        How can i access a static method(Methods in Namespace are
        static?!) from
        a method inside a class that contains a method with the same
        name?

        namespace valaDevelop
        {
             public string get_text(TextBuffer buffer, bool
        include_hidden_chars
        = true)
             {
             ...
             }

             public class abc
             {
                 public void mymethod()
                 {
                     ----> //now i want to access the static method
        above not
        the one inside the class
                 }
        public string get_text()
        {
        ...
        }

             }

        }

        I have already tried a few options, but it did not work
        "global.get_text", "valaDevelop.get_text", "::get_text" :-(


        Thanks for Help
        Wolfgang




        _______________________________________________
        vala-list mailing list
        vala-list gnome org <mailto:vala-list gnome org>
        https://mail.gnome.org/mailman/listinfo/vala-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]