topic description
Hello, everyone. I try to use inheritance and generics to make a proportional series, but the proxy framed next to the color line does not match Long. I changed the long in the protected long nextValue () method to Long, but this does not match. There are also some problems with the change. there will be problems with whether or not to change it. I would like to thank the gods, where is the fault in the end? I need you to be busy with QAQ tips
.related codes
import java.util.*;
import java.lang.*;
public class ProgressionGeneric <k> {
protected k a;
protected k b;
ProgressionGeneric(){a=b;};
protected k firstValue (){b=a;
return b;};
protected k nextValue(){return b;};
protected void printProgression(int n){
k cc=nextValue();
System.out.print(cc+" ");
for(int i=1;i<n;iPP){
k c=nextValue();
System.out.print(c+" ");
}
};
public class GeomProgression extends ProgressionGeneric<Long>{
protected long r;
GeomProgression(){ //first =1, r =1 by default
this(1,1); //first = 1; r = 1;
}
GeomProgression(long a, long base) { //Set r to base
a = a;
r = base;
}
protected long nextValue(){ long b=a; b *= r; //cur = cur*r; return b; }
}
public class Main {
public static void main(String[] args) {
GeomProgression gogo =new GeomProgression(1,4);
gogo.printProgression(3);
}