Maybe not admirals and generals, but perhaps captains or field officers. Eg Peter Noel Wylie-Buckwell.[0] From the Civil War era there's Arthur MacArthur Jr who made Captain by the age of 21. If you were to count brevetted ranks then he was Lieutenant Colonel at 19.[1]
[0] https://www.findagrave.com/memorial/55967860/peter-noel_wyli...