Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Wonder about syntax and language for two code examples

Watched this youtube video about composition and inheritance.
In this video I saw two different examples of code syntax that I have not seen before.

Generally the code looks like java but I don’t recognize these two code snippets.

Would appriciate if someone would explain what the code does and if the code is java or another language.
Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


First code:

public void replacePixel(Pixel[,] pixels] {....}

Here it is the syntax [,] that is new to me.
What does it do?


Second code:

void saveClicked(){
    file?.load(image);
}

Here is is the syntax ?.
What does it do?

Tried to use a online java compiler and the syntax did not seem to work.

>Solution :

public void replacePixel(Pixel[,] pixels) {....}

Im not sure if this is valid for Java, but in C#:

[,] here means that as an argument you want to get two-dimensional array. If you want three-dimensional array you can use [,,] and so on.

void saveClicked(){
    file?.load(image);
}

Here ? is a conditional operator that says: if file is not null then do file.load(image). Otherwise, if file is null do nothing. This can be converted to:

void saveClicked(){
    if(file != null){
        file.load(image);
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading