Conversion from a "public String" to a normal String

I am obtaining a String from the apsync.*; library. It is very reliable but I have to declare it as a
public String.

Later I am trying to compare it to a local string and get a True or false.

Here is the code simplified based on the Processing example.

  import apsync.*;
AP_Sync streamer0;


public String str0 = "CCdCP";
String str1 = str0;
String str2 = "CCCP";
// Tests to see if 'str1' is equal to 'str2'
if (str1.equals(str2) == true) {
  println("Equal");  // They are equal, so this line will print
} else {
  println("Not equal");  // This line will not print
}
I get the error:


Illegal modifier for parameter str0; only final is permitted

What am I doing wrong?
To summarize:
I want to obtain a string from AP SYNC and compare it to a local value such as "25A" or  a local string equal to that.
If they are equal , then my code should execute, etc.

Thanks


Very odd, I can reproduce it using Processing v3.5.3. You should create an issue in Processing Github. I am assuming this is caused by the error checker having a bug. Or I can create it for you. Just let me know.

Kf

I guess we found a bug. I have no idea how to make an “issue”.

Please do it for me, and all of us, lets make a better program.
This is holding my project. How long till someone will fix it, you think?

Thanks
Mitch

actually, that is correct
as it is to be used in class ( only ), and there it works.
https://processing.org/reference/public.html

class Test{
  public int a = 5;
}

while outside

public int a = 5;

always show that error.

@laptophead ===
that is not a bug, that is because in your code you are using local variables and modifiers have not any sense in this case, except for final: other modifiers have sense only for class variables which can be accessed (or not) by other classes. Writing as below and the error disappears.

public String str0 = "CCdCP";

// Tests to see if 'str1' is equal to 'str2'

void setup(){
  
  String str1 = str0;
String str2 = "CCCP";
if (str1.equals(str2) == true) {
  println("Equal");  // They are equal, so this line will print
} else {
  println("Not equal");  // This line will not print
}
}

@akenaton Thanks for your input. That makes sense.

@laptophead To explain this a bit more. When you write code in Processing, people use either use the static approach as in your provided example or they can include setup-draw functions to draw a series of frames. Processing tanspilates your code into Java. This includes arranging your code into a class. Your code above will be placed inside the setup() function. Hence, the public modifier does not apply.

Kf

1 Like

Thank you everyone, I decided not to relay on the AP SYNC anymore, and write my own strings, and split them at the other side.

One other problem was that if a public String, was “equal” with a regular string, the “equal” function was not returning a “true”,

Thanks for the feedback.
Mitch

Please provide the code to reproduce.

Kf