Java Cannot infer type arguments for “Class”
Hello so I have been trying to figure this problem out for a bit now and I googled. I have found posts on here with the same problem, but they didn't really help me.
In my JUnit test the call for
PaymentBatchProcessor checkProcessor = new PaymentBatchProcessor<>();
causes "Cannot infer type arguments for PaymentBatchProcessor<>"
I just learned about Generics and that's why I'm having such a hard time implementig it. I understand the general concept of Generics.
public class PaymentBatchProcessor <T extends Payment> {
// Variables
private T payment;
List <T> listOfPayments;
// Constructor
public PaymentBatchProcessor(T payment) {
this.payment = payment;
this.listOfPayments = new ArrayList<>();
}
// add method
public void add(T payment) {
this.listOfPayments.add(payment);
}
// getMax method
public double getMax () {
// Placeholder
double maxAmount = 0.0;
for( T payment : listOfPayments) {
// displaying each payment to console
System.out.println(payment);
// If current payment is more then current maxAmount
// assign new highest amount
if(payment.getAmount() > maxAmount) {
maxAmount = payment.getAmount();
}
}
// Return highest amount
return maxAmount;
}// END OF getMax()
// getTotal method
public double getTotal() {
// Accumulator
double total = 0.0;
// Add each payment amount to total
for( T payment : listOfPayments) {
total += payment.getAmount();
}
return total;
}// END OF getTotal()
// getSize method
public int getSize() {
// Return size of list
return listOfPayments.size();
}
}// END OF PAYMENTBATCHPROCESSOR
//Interface
public interface Payment {
public double getAmount();
public void setAmount(double amount);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Check class
public class Check implements Payment{
// Variable
private double amount;
// Constructor
public Check (double amount) {
this.amount = amount;
}
// Getter and Setter
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}// END OF CHECK
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public class IOU implements Payment {
// Variable
private double amount;
// Constructor
public IOU (double amount) {
this.amount = amount;
}
// Getter and Setter
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}// END OF IOU
}
// +++++++++++++ PROBLEM AREA +++++++++++++++++++++++++++++++++++++++++++++++++
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
public class TestGenerics
{
@Test
public void testProcessorAsCheck()
{
PaymentBatchProcessor<Check> checkProcessor = new PaymentBatchProcessor<>();
checkProcessor.add( new Check(5.00) );
checkProcessor.add (new Check(10.00) );
assertEquals(15, checkProcessor.getTotal(), 2);
assertEquals(10, checkProcessor.getMax(), 2);
}
@Test
public void testProcessorAsIOU()
{
PaymentBatchProcessor<IOU> processor = new PaymentBatchProcessor<>();
processor.add( new IOU(22.54) );
processor.add( new IOU(22.55) );
assertEquals(45.09, processor.getTotal(), 2);
assertEquals(22.55, processor.getMax(), 2);
}
@Test
public void testProcessorAsPayment()
{
Payment iou = new IOU(11.22);
Payment iou2 = new Check(22.11);
PaymentBatchProcessor<Payment> processor = new PaymentBatchProcessor<>();
processor.add(iou);
processor.add(iou2);
assertEquals(33.33, processor.getTotal(), 2);
assertEquals(22.11, processor.getMax(), 2);
}
@Test
public void testProcessorAsPaymentWithEmptyList()
{
PaymentBatchProcessor<Payment> processor = new PaymentBatchProcessor<>();
assertEquals(0, processor.getTotal(), 2);
assertNull(null, processor.getMax());
}
@Test
public void testProcessorHelperAsPayment()
{
ArrayList<Payment> list = new ArrayList<Payment>();
list.add( new Check(10.00) );
list.add( new Check(5.00) );
list.add( new IOU(1.00) );
assertEquals(10, PaymentProcessorHelper.<Payment> getMax(list).getAmount(), 2);
assertEquals(16, PaymentProcessorHelper.<Payment> getSum(list), 2);
}
@Test
public void testProcessorHelperAsPaymentEmptyList()
{
ArrayList<Payment> list = new ArrayList<Payment>();
assertNull(PaymentProcessorHelper.<Payment> getMax(list));
assertEquals(0, PaymentProcessorHelper.<Payment> getSum(list), 2);
}
@Test
public void testProcessorHelperAsCheck()
{
ArrayList<Check> list = new ArrayList<Check>();
list.add( new Check(10.00) );
list.add( new Check(5.00) );
assertEquals(10, PaymentProcessorHelper.<Check> getMax(list).getAmount(), 2);
assertEquals(15, PaymentProcessorHelper.<Check> getSum(list), 2);
}
@Test
public void testProcessorHelperAsIOU()
{
ArrayList<IOU> list = new ArrayList<IOU>();
list.add( new IOU(11.22) );
list.add( new IOU(22.11) );
assertEquals(22.11, PaymentProcessorHelper.<IOU> getMax(list).getAmount(), 2);
assertEquals(33.11, PaymentProcessorHelper.<IOU> getSum(list), 2);
}
}
java generics
|
show 1 more comment
Hello so I have been trying to figure this problem out for a bit now and I googled. I have found posts on here with the same problem, but they didn't really help me.
In my JUnit test the call for
PaymentBatchProcessor checkProcessor = new PaymentBatchProcessor<>();
causes "Cannot infer type arguments for PaymentBatchProcessor<>"
I just learned about Generics and that's why I'm having such a hard time implementig it. I understand the general concept of Generics.
public class PaymentBatchProcessor <T extends Payment> {
// Variables
private T payment;
List <T> listOfPayments;
// Constructor
public PaymentBatchProcessor(T payment) {
this.payment = payment;
this.listOfPayments = new ArrayList<>();
}
// add method
public void add(T payment) {
this.listOfPayments.add(payment);
}
// getMax method
public double getMax () {
// Placeholder
double maxAmount = 0.0;
for( T payment : listOfPayments) {
// displaying each payment to console
System.out.println(payment);
// If current payment is more then current maxAmount
// assign new highest amount
if(payment.getAmount() > maxAmount) {
maxAmount = payment.getAmount();
}
}
// Return highest amount
return maxAmount;
}// END OF getMax()
// getTotal method
public double getTotal() {
// Accumulator
double total = 0.0;
// Add each payment amount to total
for( T payment : listOfPayments) {
total += payment.getAmount();
}
return total;
}// END OF getTotal()
// getSize method
public int getSize() {
// Return size of list
return listOfPayments.size();
}
}// END OF PAYMENTBATCHPROCESSOR
//Interface
public interface Payment {
public double getAmount();
public void setAmount(double amount);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Check class
public class Check implements Payment{
// Variable
private double amount;
// Constructor
public Check (double amount) {
this.amount = amount;
}
// Getter and Setter
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}// END OF CHECK
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public class IOU implements Payment {
// Variable
private double amount;
// Constructor
public IOU (double amount) {
this.amount = amount;
}
// Getter and Setter
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}// END OF IOU
}
// +++++++++++++ PROBLEM AREA +++++++++++++++++++++++++++++++++++++++++++++++++
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
public class TestGenerics
{
@Test
public void testProcessorAsCheck()
{
PaymentBatchProcessor<Check> checkProcessor = new PaymentBatchProcessor<>();
checkProcessor.add( new Check(5.00) );
checkProcessor.add (new Check(10.00) );
assertEquals(15, checkProcessor.getTotal(), 2);
assertEquals(10, checkProcessor.getMax(), 2);
}
@Test
public void testProcessorAsIOU()
{
PaymentBatchProcessor<IOU> processor = new PaymentBatchProcessor<>();
processor.add( new IOU(22.54) );
processor.add( new IOU(22.55) );
assertEquals(45.09, processor.getTotal(), 2);
assertEquals(22.55, processor.getMax(), 2);
}
@Test
public void testProcessorAsPayment()
{
Payment iou = new IOU(11.22);
Payment iou2 = new Check(22.11);
PaymentBatchProcessor<Payment> processor = new PaymentBatchProcessor<>();
processor.add(iou);
processor.add(iou2);
assertEquals(33.33, processor.getTotal(), 2);
assertEquals(22.11, processor.getMax(), 2);
}
@Test
public void testProcessorAsPaymentWithEmptyList()
{
PaymentBatchProcessor<Payment> processor = new PaymentBatchProcessor<>();
assertEquals(0, processor.getTotal(), 2);
assertNull(null, processor.getMax());
}
@Test
public void testProcessorHelperAsPayment()
{
ArrayList<Payment> list = new ArrayList<Payment>();
list.add( new Check(10.00) );
list.add( new Check(5.00) );
list.add( new IOU(1.00) );
assertEquals(10, PaymentProcessorHelper.<Payment> getMax(list).getAmount(), 2);
assertEquals(16, PaymentProcessorHelper.<Payment> getSum(list), 2);
}
@Test
public void testProcessorHelperAsPaymentEmptyList()
{
ArrayList<Payment> list = new ArrayList<Payment>();
assertNull(PaymentProcessorHelper.<Payment> getMax(list));
assertEquals(0, PaymentProcessorHelper.<Payment> getSum(list), 2);
}
@Test
public void testProcessorHelperAsCheck()
{
ArrayList<Check> list = new ArrayList<Check>();
list.add( new Check(10.00) );
list.add( new Check(5.00) );
assertEquals(10, PaymentProcessorHelper.<Check> getMax(list).getAmount(), 2);
assertEquals(15, PaymentProcessorHelper.<Check> getSum(list), 2);
}
@Test
public void testProcessorHelperAsIOU()
{
ArrayList<IOU> list = new ArrayList<IOU>();
list.add( new IOU(11.22) );
list.add( new IOU(22.11) );
assertEquals(22.11, PaymentProcessorHelper.<IOU> getMax(list).getAmount(), 2);
assertEquals(33.11, PaymentProcessorHelper.<IOU> getSum(list), 2);
}
}
java generics
Please read stackoverflow.com/help/mcve. You should provide a minimal example, which showcases your problem. I put your code into my IDE and it compiles fine. You need to provide code, which suffers from the compilation error, which you describe.
– ygor
Nov 18 '18 at 18:42
I added the JUnit code that gives me problems at the end. Sorry
– Steven
Nov 18 '18 at 18:50
What Java version are you using? Also, what IDE?
– user10639668
Nov 18 '18 at 18:56
I just added it. I'm using Eclipse IDE, version idk, newest? the PaymentProcessorHelper is for the same class as PaymentBatchProcessor just with the two generic methods mentioned.
– Steven
Nov 18 '18 at 19:01
Your JUnit tests show a different compiler error:GenericClassPart1
is not an enclosing class. Can you confirm ? If yes, than you can find an answer here: stackoverflow.com/questions/1353309/java-static-vs-inner-class
– ygor
Nov 18 '18 at 19:55
|
show 1 more comment
Hello so I have been trying to figure this problem out for a bit now and I googled. I have found posts on here with the same problem, but they didn't really help me.
In my JUnit test the call for
PaymentBatchProcessor checkProcessor = new PaymentBatchProcessor<>();
causes "Cannot infer type arguments for PaymentBatchProcessor<>"
I just learned about Generics and that's why I'm having such a hard time implementig it. I understand the general concept of Generics.
public class PaymentBatchProcessor <T extends Payment> {
// Variables
private T payment;
List <T> listOfPayments;
// Constructor
public PaymentBatchProcessor(T payment) {
this.payment = payment;
this.listOfPayments = new ArrayList<>();
}
// add method
public void add(T payment) {
this.listOfPayments.add(payment);
}
// getMax method
public double getMax () {
// Placeholder
double maxAmount = 0.0;
for( T payment : listOfPayments) {
// displaying each payment to console
System.out.println(payment);
// If current payment is more then current maxAmount
// assign new highest amount
if(payment.getAmount() > maxAmount) {
maxAmount = payment.getAmount();
}
}
// Return highest amount
return maxAmount;
}// END OF getMax()
// getTotal method
public double getTotal() {
// Accumulator
double total = 0.0;
// Add each payment amount to total
for( T payment : listOfPayments) {
total += payment.getAmount();
}
return total;
}// END OF getTotal()
// getSize method
public int getSize() {
// Return size of list
return listOfPayments.size();
}
}// END OF PAYMENTBATCHPROCESSOR
//Interface
public interface Payment {
public double getAmount();
public void setAmount(double amount);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Check class
public class Check implements Payment{
// Variable
private double amount;
// Constructor
public Check (double amount) {
this.amount = amount;
}
// Getter and Setter
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}// END OF CHECK
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public class IOU implements Payment {
// Variable
private double amount;
// Constructor
public IOU (double amount) {
this.amount = amount;
}
// Getter and Setter
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}// END OF IOU
}
// +++++++++++++ PROBLEM AREA +++++++++++++++++++++++++++++++++++++++++++++++++
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
public class TestGenerics
{
@Test
public void testProcessorAsCheck()
{
PaymentBatchProcessor<Check> checkProcessor = new PaymentBatchProcessor<>();
checkProcessor.add( new Check(5.00) );
checkProcessor.add (new Check(10.00) );
assertEquals(15, checkProcessor.getTotal(), 2);
assertEquals(10, checkProcessor.getMax(), 2);
}
@Test
public void testProcessorAsIOU()
{
PaymentBatchProcessor<IOU> processor = new PaymentBatchProcessor<>();
processor.add( new IOU(22.54) );
processor.add( new IOU(22.55) );
assertEquals(45.09, processor.getTotal(), 2);
assertEquals(22.55, processor.getMax(), 2);
}
@Test
public void testProcessorAsPayment()
{
Payment iou = new IOU(11.22);
Payment iou2 = new Check(22.11);
PaymentBatchProcessor<Payment> processor = new PaymentBatchProcessor<>();
processor.add(iou);
processor.add(iou2);
assertEquals(33.33, processor.getTotal(), 2);
assertEquals(22.11, processor.getMax(), 2);
}
@Test
public void testProcessorAsPaymentWithEmptyList()
{
PaymentBatchProcessor<Payment> processor = new PaymentBatchProcessor<>();
assertEquals(0, processor.getTotal(), 2);
assertNull(null, processor.getMax());
}
@Test
public void testProcessorHelperAsPayment()
{
ArrayList<Payment> list = new ArrayList<Payment>();
list.add( new Check(10.00) );
list.add( new Check(5.00) );
list.add( new IOU(1.00) );
assertEquals(10, PaymentProcessorHelper.<Payment> getMax(list).getAmount(), 2);
assertEquals(16, PaymentProcessorHelper.<Payment> getSum(list), 2);
}
@Test
public void testProcessorHelperAsPaymentEmptyList()
{
ArrayList<Payment> list = new ArrayList<Payment>();
assertNull(PaymentProcessorHelper.<Payment> getMax(list));
assertEquals(0, PaymentProcessorHelper.<Payment> getSum(list), 2);
}
@Test
public void testProcessorHelperAsCheck()
{
ArrayList<Check> list = new ArrayList<Check>();
list.add( new Check(10.00) );
list.add( new Check(5.00) );
assertEquals(10, PaymentProcessorHelper.<Check> getMax(list).getAmount(), 2);
assertEquals(15, PaymentProcessorHelper.<Check> getSum(list), 2);
}
@Test
public void testProcessorHelperAsIOU()
{
ArrayList<IOU> list = new ArrayList<IOU>();
list.add( new IOU(11.22) );
list.add( new IOU(22.11) );
assertEquals(22.11, PaymentProcessorHelper.<IOU> getMax(list).getAmount(), 2);
assertEquals(33.11, PaymentProcessorHelper.<IOU> getSum(list), 2);
}
}
java generics
Hello so I have been trying to figure this problem out for a bit now and I googled. I have found posts on here with the same problem, but they didn't really help me.
In my JUnit test the call for
PaymentBatchProcessor checkProcessor = new PaymentBatchProcessor<>();
causes "Cannot infer type arguments for PaymentBatchProcessor<>"
I just learned about Generics and that's why I'm having such a hard time implementig it. I understand the general concept of Generics.
public class PaymentBatchProcessor <T extends Payment> {
// Variables
private T payment;
List <T> listOfPayments;
// Constructor
public PaymentBatchProcessor(T payment) {
this.payment = payment;
this.listOfPayments = new ArrayList<>();
}
// add method
public void add(T payment) {
this.listOfPayments.add(payment);
}
// getMax method
public double getMax () {
// Placeholder
double maxAmount = 0.0;
for( T payment : listOfPayments) {
// displaying each payment to console
System.out.println(payment);
// If current payment is more then current maxAmount
// assign new highest amount
if(payment.getAmount() > maxAmount) {
maxAmount = payment.getAmount();
}
}
// Return highest amount
return maxAmount;
}// END OF getMax()
// getTotal method
public double getTotal() {
// Accumulator
double total = 0.0;
// Add each payment amount to total
for( T payment : listOfPayments) {
total += payment.getAmount();
}
return total;
}// END OF getTotal()
// getSize method
public int getSize() {
// Return size of list
return listOfPayments.size();
}
}// END OF PAYMENTBATCHPROCESSOR
//Interface
public interface Payment {
public double getAmount();
public void setAmount(double amount);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Check class
public class Check implements Payment{
// Variable
private double amount;
// Constructor
public Check (double amount) {
this.amount = amount;
}
// Getter and Setter
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}// END OF CHECK
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public class IOU implements Payment {
// Variable
private double amount;
// Constructor
public IOU (double amount) {
this.amount = amount;
}
// Getter and Setter
public double getAmount() {
return this.amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}// END OF IOU
}
// +++++++++++++ PROBLEM AREA +++++++++++++++++++++++++++++++++++++++++++++++++
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
public class TestGenerics
{
@Test
public void testProcessorAsCheck()
{
PaymentBatchProcessor<Check> checkProcessor = new PaymentBatchProcessor<>();
checkProcessor.add( new Check(5.00) );
checkProcessor.add (new Check(10.00) );
assertEquals(15, checkProcessor.getTotal(), 2);
assertEquals(10, checkProcessor.getMax(), 2);
}
@Test
public void testProcessorAsIOU()
{
PaymentBatchProcessor<IOU> processor = new PaymentBatchProcessor<>();
processor.add( new IOU(22.54) );
processor.add( new IOU(22.55) );
assertEquals(45.09, processor.getTotal(), 2);
assertEquals(22.55, processor.getMax(), 2);
}
@Test
public void testProcessorAsPayment()
{
Payment iou = new IOU(11.22);
Payment iou2 = new Check(22.11);
PaymentBatchProcessor<Payment> processor = new PaymentBatchProcessor<>();
processor.add(iou);
processor.add(iou2);
assertEquals(33.33, processor.getTotal(), 2);
assertEquals(22.11, processor.getMax(), 2);
}
@Test
public void testProcessorAsPaymentWithEmptyList()
{
PaymentBatchProcessor<Payment> processor = new PaymentBatchProcessor<>();
assertEquals(0, processor.getTotal(), 2);
assertNull(null, processor.getMax());
}
@Test
public void testProcessorHelperAsPayment()
{
ArrayList<Payment> list = new ArrayList<Payment>();
list.add( new Check(10.00) );
list.add( new Check(5.00) );
list.add( new IOU(1.00) );
assertEquals(10, PaymentProcessorHelper.<Payment> getMax(list).getAmount(), 2);
assertEquals(16, PaymentProcessorHelper.<Payment> getSum(list), 2);
}
@Test
public void testProcessorHelperAsPaymentEmptyList()
{
ArrayList<Payment> list = new ArrayList<Payment>();
assertNull(PaymentProcessorHelper.<Payment> getMax(list));
assertEquals(0, PaymentProcessorHelper.<Payment> getSum(list), 2);
}
@Test
public void testProcessorHelperAsCheck()
{
ArrayList<Check> list = new ArrayList<Check>();
list.add( new Check(10.00) );
list.add( new Check(5.00) );
assertEquals(10, PaymentProcessorHelper.<Check> getMax(list).getAmount(), 2);
assertEquals(15, PaymentProcessorHelper.<Check> getSum(list), 2);
}
@Test
public void testProcessorHelperAsIOU()
{
ArrayList<IOU> list = new ArrayList<IOU>();
list.add( new IOU(11.22) );
list.add( new IOU(22.11) );
assertEquals(22.11, PaymentProcessorHelper.<IOU> getMax(list).getAmount(), 2);
assertEquals(33.11, PaymentProcessorHelper.<IOU> getSum(list), 2);
}
}
java generics
java generics
edited Nov 21 '18 at 5:54
Steven
asked Nov 18 '18 at 18:19
StevenSteven
246
246
Please read stackoverflow.com/help/mcve. You should provide a minimal example, which showcases your problem. I put your code into my IDE and it compiles fine. You need to provide code, which suffers from the compilation error, which you describe.
– ygor
Nov 18 '18 at 18:42
I added the JUnit code that gives me problems at the end. Sorry
– Steven
Nov 18 '18 at 18:50
What Java version are you using? Also, what IDE?
– user10639668
Nov 18 '18 at 18:56
I just added it. I'm using Eclipse IDE, version idk, newest? the PaymentProcessorHelper is for the same class as PaymentBatchProcessor just with the two generic methods mentioned.
– Steven
Nov 18 '18 at 19:01
Your JUnit tests show a different compiler error:GenericClassPart1
is not an enclosing class. Can you confirm ? If yes, than you can find an answer here: stackoverflow.com/questions/1353309/java-static-vs-inner-class
– ygor
Nov 18 '18 at 19:55
|
show 1 more comment
Please read stackoverflow.com/help/mcve. You should provide a minimal example, which showcases your problem. I put your code into my IDE and it compiles fine. You need to provide code, which suffers from the compilation error, which you describe.
– ygor
Nov 18 '18 at 18:42
I added the JUnit code that gives me problems at the end. Sorry
– Steven
Nov 18 '18 at 18:50
What Java version are you using? Also, what IDE?
– user10639668
Nov 18 '18 at 18:56
I just added it. I'm using Eclipse IDE, version idk, newest? the PaymentProcessorHelper is for the same class as PaymentBatchProcessor just with the two generic methods mentioned.
– Steven
Nov 18 '18 at 19:01
Your JUnit tests show a different compiler error:GenericClassPart1
is not an enclosing class. Can you confirm ? If yes, than you can find an answer here: stackoverflow.com/questions/1353309/java-static-vs-inner-class
– ygor
Nov 18 '18 at 19:55
Please read stackoverflow.com/help/mcve. You should provide a minimal example, which showcases your problem. I put your code into my IDE and it compiles fine. You need to provide code, which suffers from the compilation error, which you describe.
– ygor
Nov 18 '18 at 18:42
Please read stackoverflow.com/help/mcve. You should provide a minimal example, which showcases your problem. I put your code into my IDE and it compiles fine. You need to provide code, which suffers from the compilation error, which you describe.
– ygor
Nov 18 '18 at 18:42
I added the JUnit code that gives me problems at the end. Sorry
– Steven
Nov 18 '18 at 18:50
I added the JUnit code that gives me problems at the end. Sorry
– Steven
Nov 18 '18 at 18:50
What Java version are you using? Also, what IDE?
– user10639668
Nov 18 '18 at 18:56
What Java version are you using? Also, what IDE?
– user10639668
Nov 18 '18 at 18:56
I just added it. I'm using Eclipse IDE, version idk, newest? the PaymentProcessorHelper is for the same class as PaymentBatchProcessor just with the two generic methods mentioned.
– Steven
Nov 18 '18 at 19:01
I just added it. I'm using Eclipse IDE, version idk, newest? the PaymentProcessorHelper is for the same class as PaymentBatchProcessor just with the two generic methods mentioned.
– Steven
Nov 18 '18 at 19:01
Your JUnit tests show a different compiler error:
GenericClassPart1
is not an enclosing class. Can you confirm ? If yes, than you can find an answer here: stackoverflow.com/questions/1353309/java-static-vs-inner-class– ygor
Nov 18 '18 at 19:55
Your JUnit tests show a different compiler error:
GenericClassPart1
is not an enclosing class. Can you confirm ? If yes, than you can find an answer here: stackoverflow.com/questions/1353309/java-static-vs-inner-class– ygor
Nov 18 '18 at 19:55
|
show 1 more comment
1 Answer
1
active
oldest
votes
For PaymentBatchProcessor
you have defined a constructor that takes a Payment
as an argument, but in the tests you try to use a no-arguments constructor new PaymentBatchProcessor<>()
, which doesn't exist.
You either need to define a no-arguments constructor or provide an argument to the constructors in your tests.
And I'm also trying to make getMax and getTotal a generic method
Based on the code in your question I don't really understand why you would want to do that.
I tried making them public static < T >
I think you have misunderstood something about generics (and also the static
modifier) here.
It doesn't look like getMax
and getTotal
should ever return anything other than double
and they don't take any arguments so there is no issue of handling different types of inputs.
And you can't make those methods static
because they operate on instance variables (not class variables).
You have only posted code aboutPaymentBatchProcessor
notPaymentProcessorHelper
in your question. If you tried to make the methods ofPaymentBatchProcessor
generic then that's probably wrong. If you tried to make methods ofPaymentProcessorHelper
generic and it didn't work then you have probably copied something over fromPaymentBatchProcessor
that you shouldn't have. Either way I suggest working through this tutorial if you haven't already docs.oracle.com/javase/tutorial/java/generics
– binoternary
Nov 19 '18 at 7:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364089%2fjava-cannot-infer-type-arguments-for-class%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For PaymentBatchProcessor
you have defined a constructor that takes a Payment
as an argument, but in the tests you try to use a no-arguments constructor new PaymentBatchProcessor<>()
, which doesn't exist.
You either need to define a no-arguments constructor or provide an argument to the constructors in your tests.
And I'm also trying to make getMax and getTotal a generic method
Based on the code in your question I don't really understand why you would want to do that.
I tried making them public static < T >
I think you have misunderstood something about generics (and also the static
modifier) here.
It doesn't look like getMax
and getTotal
should ever return anything other than double
and they don't take any arguments so there is no issue of handling different types of inputs.
And you can't make those methods static
because they operate on instance variables (not class variables).
You have only posted code aboutPaymentBatchProcessor
notPaymentProcessorHelper
in your question. If you tried to make the methods ofPaymentBatchProcessor
generic then that's probably wrong. If you tried to make methods ofPaymentProcessorHelper
generic and it didn't work then you have probably copied something over fromPaymentBatchProcessor
that you shouldn't have. Either way I suggest working through this tutorial if you haven't already docs.oracle.com/javase/tutorial/java/generics
– binoternary
Nov 19 '18 at 7:59
add a comment |
For PaymentBatchProcessor
you have defined a constructor that takes a Payment
as an argument, but in the tests you try to use a no-arguments constructor new PaymentBatchProcessor<>()
, which doesn't exist.
You either need to define a no-arguments constructor or provide an argument to the constructors in your tests.
And I'm also trying to make getMax and getTotal a generic method
Based on the code in your question I don't really understand why you would want to do that.
I tried making them public static < T >
I think you have misunderstood something about generics (and also the static
modifier) here.
It doesn't look like getMax
and getTotal
should ever return anything other than double
and they don't take any arguments so there is no issue of handling different types of inputs.
And you can't make those methods static
because they operate on instance variables (not class variables).
You have only posted code aboutPaymentBatchProcessor
notPaymentProcessorHelper
in your question. If you tried to make the methods ofPaymentBatchProcessor
generic then that's probably wrong. If you tried to make methods ofPaymentProcessorHelper
generic and it didn't work then you have probably copied something over fromPaymentBatchProcessor
that you shouldn't have. Either way I suggest working through this tutorial if you haven't already docs.oracle.com/javase/tutorial/java/generics
– binoternary
Nov 19 '18 at 7:59
add a comment |
For PaymentBatchProcessor
you have defined a constructor that takes a Payment
as an argument, but in the tests you try to use a no-arguments constructor new PaymentBatchProcessor<>()
, which doesn't exist.
You either need to define a no-arguments constructor or provide an argument to the constructors in your tests.
And I'm also trying to make getMax and getTotal a generic method
Based on the code in your question I don't really understand why you would want to do that.
I tried making them public static < T >
I think you have misunderstood something about generics (and also the static
modifier) here.
It doesn't look like getMax
and getTotal
should ever return anything other than double
and they don't take any arguments so there is no issue of handling different types of inputs.
And you can't make those methods static
because they operate on instance variables (not class variables).
For PaymentBatchProcessor
you have defined a constructor that takes a Payment
as an argument, but in the tests you try to use a no-arguments constructor new PaymentBatchProcessor<>()
, which doesn't exist.
You either need to define a no-arguments constructor or provide an argument to the constructors in your tests.
And I'm also trying to make getMax and getTotal a generic method
Based on the code in your question I don't really understand why you would want to do that.
I tried making them public static < T >
I think you have misunderstood something about generics (and also the static
modifier) here.
It doesn't look like getMax
and getTotal
should ever return anything other than double
and they don't take any arguments so there is no issue of handling different types of inputs.
And you can't make those methods static
because they operate on instance variables (not class variables).
edited Nov 19 '18 at 0:48
answered Nov 18 '18 at 22:46
binoternarybinoternary
1,4851919
1,4851919
You have only posted code aboutPaymentBatchProcessor
notPaymentProcessorHelper
in your question. If you tried to make the methods ofPaymentBatchProcessor
generic then that's probably wrong. If you tried to make methods ofPaymentProcessorHelper
generic and it didn't work then you have probably copied something over fromPaymentBatchProcessor
that you shouldn't have. Either way I suggest working through this tutorial if you haven't already docs.oracle.com/javase/tutorial/java/generics
– binoternary
Nov 19 '18 at 7:59
add a comment |
You have only posted code aboutPaymentBatchProcessor
notPaymentProcessorHelper
in your question. If you tried to make the methods ofPaymentBatchProcessor
generic then that's probably wrong. If you tried to make methods ofPaymentProcessorHelper
generic and it didn't work then you have probably copied something over fromPaymentBatchProcessor
that you shouldn't have. Either way I suggest working through this tutorial if you haven't already docs.oracle.com/javase/tutorial/java/generics
– binoternary
Nov 19 '18 at 7:59
You have only posted code about
PaymentBatchProcessor
not PaymentProcessorHelper
in your question. If you tried to make the methods of PaymentBatchProcessor
generic then that's probably wrong. If you tried to make methods of PaymentProcessorHelper
generic and it didn't work then you have probably copied something over from PaymentBatchProcessor
that you shouldn't have. Either way I suggest working through this tutorial if you haven't already docs.oracle.com/javase/tutorial/java/generics– binoternary
Nov 19 '18 at 7:59
You have only posted code about
PaymentBatchProcessor
not PaymentProcessorHelper
in your question. If you tried to make the methods of PaymentBatchProcessor
generic then that's probably wrong. If you tried to make methods of PaymentProcessorHelper
generic and it didn't work then you have probably copied something over from PaymentBatchProcessor
that you shouldn't have. Either way I suggest working through this tutorial if you haven't already docs.oracle.com/javase/tutorial/java/generics– binoternary
Nov 19 '18 at 7:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364089%2fjava-cannot-infer-type-arguments-for-class%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please read stackoverflow.com/help/mcve. You should provide a minimal example, which showcases your problem. I put your code into my IDE and it compiles fine. You need to provide code, which suffers from the compilation error, which you describe.
– ygor
Nov 18 '18 at 18:42
I added the JUnit code that gives me problems at the end. Sorry
– Steven
Nov 18 '18 at 18:50
What Java version are you using? Also, what IDE?
– user10639668
Nov 18 '18 at 18:56
I just added it. I'm using Eclipse IDE, version idk, newest? the PaymentProcessorHelper is for the same class as PaymentBatchProcessor just with the two generic methods mentioned.
– Steven
Nov 18 '18 at 19:01
Your JUnit tests show a different compiler error:
GenericClassPart1
is not an enclosing class. Can you confirm ? If yes, than you can find an answer here: stackoverflow.com/questions/1353309/java-static-vs-inner-class– ygor
Nov 18 '18 at 19:55