Q
qazmlp
Can't Template method pattern be used in Java?
I just wanted to translate the following C++ code:
class ClassBase
{
// Other members
public:
void setData(const std::vector<std::string>& dataVec);
private:
virtual void doSetData(const std::vector<std::string>& dataVec) = 0;
};
into this Java code:
public abstract class ClassBase
{
// Other members
public void setData( final Vector dataVec) { }
private abstract void doSetData( Vector dataVec );
}
But, the Java compiler reports the following error:
ClassBase.java:11: Abstract methods can't be private: void doSetData(Vector)
private abstract void doSetData( Vector dataVec );
Why is this so? Then, what is the alternative for my above C++ class in Java?
Thanks!
I just wanted to translate the following C++ code:
class ClassBase
{
// Other members
public:
void setData(const std::vector<std::string>& dataVec);
private:
virtual void doSetData(const std::vector<std::string>& dataVec) = 0;
};
into this Java code:
public abstract class ClassBase
{
// Other members
public void setData( final Vector dataVec) { }
private abstract void doSetData( Vector dataVec );
}
But, the Java compiler reports the following error:
ClassBase.java:11: Abstract methods can't be private: void doSetData(Vector)
private abstract void doSetData( Vector dataVec );
Why is this so? Then, what is the alternative for my above C++ class in Java?
Thanks!