-
Notifications
You must be signed in to change notification settings - Fork 21
Can't access protected static inner classes of extended classes #1806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1806?orig=1 |
@dragos said: |
@milessabin said: We've worked around similar examples at the Scala/Java border previously and I think we should finish the job off properly. It's been on my TODO list to take a look at this myself, and I'd rather keep this bug open as a reminder that it really should be addressed at some point. Unless you really do want to limit interoperability with Java in this area, in which case wontfix it again. But I think that would be a shame. |
@paulp said: If people can't count on smooth interoperation with java, the case to be made for scala is very badly damaged. |
@jrudolph said: The workaround is to create an abstract class in Java implementing the interface which wraps accesses to the inner class. One may then implement this abstract class from Scala. In this particular case: #!java
import android.widget.BaseAdapter;
import android.widget.Filter;
public abstract class MyFilter<T> extends Filter{
private final BaseAdapter parent;
public MyFilter(BaseAdapter parent) {
this.parent = parent;
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults res = new FilterResults();
T value = getResult(constraint);
res.values = value;
res.count = countFromData(value);
return res;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults res) {
setData(res.count,(T) res.values);
if (res.count == 0)
parent.notifyDataSetInvalidated();
else
parent.notifyDataSetChanged();
}
protected abstract void setData(int count,T data);
protected abstract int countFromData(T data);
protected abstract T getResult(CharSequence constraint);
} Hmm, I think I understand the problem: Scala interprets the Java class ( BTW: Why does the import work, shouldn't that be disallowed as well? |
@odersky said: Brad Abrams : New Design Guideline: Avoid Protected Static There's no way we can simulate static protected without impairing the integrity of Scala's object model in a fundamental way. I refuse to let that happen. So, please keep the bug closed. We have been several times through this. I think it's unlikely I will change my position. |
@paulp said: |
@milessabin said: I can see complications which would make it quite reasonable for you to toss it to the community and ask for patches. But I can think of at least one line of attack which wouldn't impair the integrity of Scala's object model in a fundamental way. Can you point to somewhere that the compromise of Scala's object model has been explained? |
@milessabin said: Also ... what Paul said: treating those Java statics as public would do the trick without in any way compromising the Scala object model or type system. |
@jrudolph said: |
@paulp said: |
Given a Java class defined like this:
It is not possible to implement this class in Scala from another package:
This aside, Inner is not in scope as you would expect it to be:
The text was updated successfully, but these errors were encountered: