Re: I need to know if a java class import a package
Daniel wrote:
Eric, thanks for your help
To clarify a little bit more my problem, I will try to add some
example of what I'm needing:
I need that some users fill with code in page to solve a task, this
task involves the sorting of an array of integers, this could be
easily solved with Collections.sort, but I gave them as a
precondition, they couldn't use the Collections class (because I want
to test if they can iterate an order an array by themselves).
I didn't read everything, but I wonder if some form of dependancy
injection would work here. You supply the object (let's call it
SortTest) to sort, rather than allow them to declare one internally.
Also, make each method call for SortTest, for a read or a write, record
what is being done. So if they are supposed to be implementing a shell
sort, you'll know if the reads and writes for the object are being done
in the correct order. This could be useful feedback for the student, to
point out common errors. If on the other hand they read each element
once, in order, then write them back once, in the sorted order, they are
probably cheating.
Rather than calling main, I think you'd have to define your own
Interface, which the user would then implement. Do the compile and run
both on your end, that way you can control which libraries are accessed.
You could also define your own classloader, to deny access to certain
classes by the user.