0

I have my small framework wrote in C# and SeleniumWebDriver and now I want to learn Java. I try to create new framework in Java according to my C# framework and I have problem with some code related with get and set because in Java that not exist.

In Java I tried to rewrite this but without any success and I haven't got already any idea.

This is my C# code which i need to write in Java:

 private static IWebDriver _driver;

 public static IWebDriver Driver
        {
            get
            {
                if (_driver == null)
                {
                    InitializeDriver();
                }

                return _driver;
            }
            private set => _driver = value;
        }

It is possible to write this C# code in Java? Correction. Could somebody show me how to do it? Thanks a lot for respond.


  • 3
    Side note : I would not call it refactoring but "Porting" or "Converting". But the answer is - it is possible. – Michał Krzywański Oct 02 '19 at 08:48
  • Possible duplicate of [What is an efficient way to implement a singleton pattern in Java?](https://stackoverflow.com/questions/70689/what-is-an-efficient-way-to-implement-a-singleton-pattern-in-java) – Guy Oct 02 '19 at 08:49

1 Answers1

1

try this.

private static IWebDriver driver;

public static void SetDriver(IWebDriver Driver) {
    driver = Driver;
}

public static IWebDriver GetDriver() {
    return driver;
}

this is Eclipse Getter/Setter Generated form.

you can also use generate getter and setters function in Eclipse menu

[Source > Generate Getter and Setters ]

Arphile
  • 841
  • 6
  • 18
  • 2
    Isn't the default naming convention for methods in java to use camelCase? If so, why does eclipse use PascalCase? – Joelius Oct 02 '19 at 09:04
  • @Joelius sorry, I put code manually. this is my pattern to code.default is camelCase as you told. – Arphile Oct 02 '19 at 15:01