I don't understand this; you have interface ATable :
public interface ATable {
String getCurrentUserName();
String getTableName();
}
Then you create object:
ATable aTable = new ATable() {
@Override
public String getCurrentUserName() {
return "Amigo";
}
@Override
public String getTableName() {
return "DashboardTable";
}
};
I thought you aren't able to create objects from interfaces, only to implement them in other classes.package com.codegym.task.task19.task1901;
/*
TableAdapter
*/
public class Solution {
public static void main(String[] args) {
ATable aTable = new ATable() {
@Override
public String getCurrentUserName() {
return "Amigo";
}
@Override
public String getTableName() {
return "DashboardTable";
}
};
BTable table = new TableAdapter(aTable);
System.out.println(table.getHeaderText());
}
public static class TableAdapter implements BTable {
private ATable aTable;
public TableAdapter (ATable aTable){
this.aTable = aTable;
}
@Override
public String getHeaderText() {
return "[" + aTable.getCurrentUserName() + "3] : " + aTable.getTableName() ;
}
}
public interface ATable {
String getCurrentUserName();
String getTableName();
}
public interface BTable {
String getHeaderText();
}
}